I have following code:
class Base
{
public:
Base(int test) { std::cout << "Base constructor, test: " << test << std::endl; }
};
class Derived : public Base
{
private:
int variable;
public:
Derived() :
variable(50),
Base(variable)
{}
};
Derived derived;
And I would expect that output would be: "Base constructor, test: 50", but that isn't the case, because Base
constructor gets called before variable
is initialized, there is no error nor warning, it just compiles.
Is there any way i can make Base
constructor get called after ? Or is this generally bad design ?
I'm tryting to get rid of all the init methods and their calls by putting them into constructor insted, this behavior stop me from doing that.