In the SuperCar constructor, add : Car(... your arguments ...) between the constructor header and the constructor body.
Code example:
#include <iostream> using namespace std; class Car { public: Car() { } // Oh, there is several constructors... Car(int weight){ cout << "Car weight is " << weight << endl; } }; class SuperCar: public Car { public: // we call the right constructor for Car, detected by call arguments // relying on usual function overloading mechanism SuperCar(int weight, int height) : Car(weight) { cout << "SuperCar height " << height << endl; } }; int main(){ SuperCar(1, 10); }
PS: By the way, calling the SuperCar subclass of Car confusing, you should probably avoid this.
kriss source share