Hi i have a problem with object composition. The class CInvoice needs to have a CCustomer object inside, so I created a constructor that requires a customer.
In Invoice.h file there is a line:
CCustomer *customer;
And the mentioned constructor looks like this:
CInvoice::CInvoice(CCustomer Customer)
{
customer = &Customer;
}
When I try to print the name of the customer on the invoice it returns some random characters
CCustomer customer("McDonalds", "Boston, Massachusetts", 4);
CInvoice invoice(customer);
cout << "Customer:" << customer.GetName() << endl; //it prints "McDonalds"
cout << "Invoice.Customer:" << invoice.customer->GetName() << endl; // it prints random characters
Have I implemented the object composition properly?
Also I have a class CInvoiceElement and have a question about it. Should I create invoice elements without having the invoice object created or the other way around? Which is more logical?