Link to home
Start Free TrialLog in
Avatar of oggiemc
oggiemcFlag for Ireland

asked on

Objects in constructor Parameter list

Hi all,

Im a little bit confused on the syntax used for constructors of a class which have objects in their Parameter list..Perhaps somebody can explain the attached code to me? The line that is confusing to me is:

Vehicle(v), numberSeats(_numberSeats), numberDoors

how does the constructor know what parameters/types v has?? Can someone explain to me what exactly is going on when objects are passed to constructors like this?

Thanks
class Vehicle{

  string color;
  string brandName;

 public:
  Vehicle(string, string);
  virtual void display();
};

class Car: public Vehicle{
      
  int numberSeats, numberDoors, numberWheels;

 public:
  Car(string, string, int, int, int);
  Car(Vehicle, int, int, int);
  virtual void display();
};

Vehicle::Vehicle(string _color, string _brandName):color(_color)
                , brandName(_brandName){}
                
      
Car::Car(Vehicle v, int _numberSeats,int _numberDoors, int _numberWheels):
         Vehicle(v), numberSeats(_numberSeats), numberDoors  //I dont understand Vehicle (v)
         (_numberDoors), numberWheels(_numberWheels){}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jhshukla
jhshukla
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of phoffric
phoffric

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial