Aggregation relationship and pointer

I have some question with the pointer, how should I do if I want to add the item array into a customer?

1
2
3
4
5
6
7
8
9
10
for(int i=0; i<numItem; i++)
				{
					data[choice2-1].setQuantity(quantity);
				/*	custList[i]->addItem(data);
					data[i].Item(choice2-1, quantity);
					itemPtr = &data[i];*/
				}

				//Add the item to the selected Customer object
				//movieList[choice2-1].addAudience(audiencePtr); 
Is this the list of Item thing we discussed in a different thread? Can you post the definition of Item again please.

Found it:
1
2
3
4
5
6
7
8
9
10
11
class Item
{
public:
	string code;
	string name;
	int quantity;
	double totPrice;
	double itemPrice;
	Date date;
	Time time;
// ... 


Assuming Customer has definition:
1
2
3
4
5
std::vector<Item> items;

void addItems(const Item& item) const {
    items.push_back(item);
}


You can write code like:
1
2
3
4
5
{
    Item item;
    // code that fills in item
    customer.addItem(item);
}


No pointers.
Last edited on
Ouh I see, thank you so much!
Topic archived. No new replies allowed.