Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constructors and inheritance?

Tags:

c++

Lets say I have a class named Car and another which inherits from Car called SuperCar. How can I ensure that Car's costructor is called in SuperCar's constructor? Do I simply do: Car.Car(//args);?

Thanks

like image 257
jmasterx Avatar asked Dec 12 '22 19:12

jmasterx


1 Answers

Sample classes with no member vars.

class Car { 
            Car(); /*If you want default objects*/
            Car(/*arg list*/); /* maybe multiple constructors with different, count and 
                                type args */
};

class SuperCar {
           SuperCar(/*args list*/) : Car(/*arg list*/){/*Constructor Body*/}
};
like image 56
DumbCoder Avatar answered Dec 27 '22 01:12

DumbCoder