Shopping list program have some issues

I am working on a program that maintain list of items. The way to do it is that I created two classes, the first is List class, the second is Items class. Obviously the items class has: string name, unit; int quantity, float price, as private member variables, and I used accessors and mutators to set and get them. In the list calss: I have add_item function, and print_list function (both void). In the List constructor I have created a dynamic array to hold the items in a list. So, as you may guess, ONE LIST OBJECT WILL HAVE MANY ITEM OBJECTS.

My problem is that I don't know how to work the add_item function, and I want someone to review my print_list function too.

Help is appreciated a lot. Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void List::add_item(Items& theItem){
        string _name; // I have those as private member variables in Items class
        string _unit; // However, I have " Items *item " in List.hpp
        int _quantity;
        float _price;
        for(int i=0; i<arraySize; i++){
                theItem[i].set_name(_name); // it does not like the [i]
                theItem[i].set_unit(_unit); // it says "no match for operator[]"
                theItem[i].set_quantity(_quantity);
                theItem[i].set_price(_price);
        }
                item[elements]=theItem;
                elements+=1;
}


Can someone help to debug this function? I am trying to build a function that adds the item object (passed in the function) to the dynamic array.
What am I doing wrong?

Thank A lot.
Topic archived. No new replies allowed.