I just want to do some adjusts before launching the parent's creator. Is it possible? If no, how would you solve this?
#include <iostream>
using namespace std;
class vehicle
{
protected:
string type = "vehicle";
public:
vehicle() { cout << type << " created" <<endl; }
void what_am_i() { cout << "I am a " << type <<endl;}
};
class car: public vehicle
{
public:
car()
{
type = "car";
//I would like to launch vehicle() here ;
}
};
int main()
{
car Lorean;
Lorean.what_am_i();
}
Current result:
vehicle created
I am a car
Wanted result:
car created
I am a car
PD: The constructor output is just an example. I need to launch some processes in the parent's creator which use many attributes that must to updated in each child class. The process are exactly the same in all of them, so It would be wonderful that all of them run in the parent creator.
PPD: To illustrate what I hoped to do with C++, please look what I have done with Python3. Here parent's creator can be launched any time, even never (this behaviour seems to be imposible with C++):
class vehiculo:
tipo = "vehiculo"
def __init__(self): print(self.tipo.capitalize() ,"creado.")
def que_soy(self): print("Soy un",self.tipo)
class automovil(vehiculo):
def __init__(self):
self.tipo = "automovil"
super().__init__()
Lorean = automovil()
Lorean.que_soy()
Current and wanted result:
Automovil creado.
Soy un automovil