私はC++を学んでいて、ポインターに問題があります。
この単純なプロジェクトは、顧客へのポインタを含む請求書で構成されています。
クラス:
class Customer {
string name;
public:
Customer(string name) { this->name = name; };
string getName() { return name; };
void changeName(string name) { this->name = name; };
};
class Invoice {
Customer * customer;
public:
Invoice(Customer *customer) { this->customer = customer; };
Customer getCustomer() { return *customer; };
};
主要:
Customer *customer1 = new Customer("Name 1");
Invoice invoice1(customer1);
cout << invoice1.getCustomer().getName() << endl; //Return:Name 1;
これを機能させるためにCustomer::changeName(string name)を使用するにはどうすればよいですか?
(...) changeName("Name 2");
cout << invoice1.getCustomer().getName() << endl; //Return:Name 2;
お客様の名前を変更するために何を使用すればよいかわかりません。または、クラスの請求書で何か問題が発生している可能性があります。
なぜ請求書で名前を変更するのですか?
そのため、プロジェクトが大きくなり始める前に、ポインターの使用方法を学ぶことができます。
後で、請求書のベクトルと顧客のベクトルを作成します。請求書または顧客のベクトルから顧客へのポインタを取得することは同じである必要があります。
ありがとう、
エドゥアルド