0

How do you go about initializing all the objects by the constructor?

Suppose you have 4 Set objects inside a Location class. How do you initialize the 4 set objects from the constructor to set as default? I tried to first create the objects already initialized :

Set nyX (nyXv); And then try to put it inside the constructor, but that will not work.

class Location
{
public:
    vector<int> nyXv = { 0, 1, 2, 3, 4, 5};
    vector<int> nyYv = { 0, 1, 2, 3, 4, 5 };

    vector<int> sfXv = { 6, 7, 8, 9, 10 };
    vector<int> sfYv = { 6, 7, 8, 9, 10 };


    Set nyX;
    Set nyY;

    Set sfX;
    Set sfY;


    Location();
    ~Location();

};



class Set
{
public:
    Set(vector<int> &);
};
monkey doodle
  • 690
  • 5
  • 12
  • 22

1 Answers1

1

You should use an initialization list:

Location::Location()
  : nyX(nyXv)
{}
John Zwinck
  • 239,568
  • 38
  • 324
  • 436