Accessing/Storing values using Push_back()

If I have the following car class which just stores name and price:

1
2
3
4
5
6
7
8
9
10
11
12
13
class car
{

   private:
      string name;
      int price;
   private:
      //constructors/destructors
      void setCarName(string nm){name = nm;}
      void setCarPrice(int rrp){price = rrp;}
      string getCarName(){return name;}
      int getCarPrice(){return price;}
}


And a company class which stores the company name, as well as a list of the car class:

1
2
3
4
5
6
7
8
9
10
11
class company
{

   private:
      string cpname;
      list <car> carList;
   public:
      //constructors/destructors
      void setCompanyName(string cnm){cpname = cnm;}
      string getCompanyName(){return cpname;}
}


Then I do this in main:

list <company> companyList;

And add an entry to the company list like this:

companyList.push_back(companyname);

How do I add/store values for the car class (name, price) using push_back?
Last edited on
closed account (S6k9GNh0)
http://cplusplus.com/reference/stl/list/push_back/
Topic archived. No new replies allowed.