I have a Car class that inherits a Vehicle class. Both the Car and Vehicle class takes in the parameter, ‘wheels’. From my understanding of how inheritance works, the object Car would be constructed in two phases: Vehicle would construct first by calling its Constructor, followed by Car which would also call its constructor. My question is how would I write my Car’s constructor when its parameters are being used by the Vehicle’s constructor?
class Vehicle {
public:
Vehicle(int wheels);
};
class Car {
public:
Car(int wheels): Vehicle(wheels);
};
You need to inherit from Vehicle:
Header file:
Cpp file: