Are parent class constructors called before initializing variables, or will the compiler initialize the variables of the class first?
For example:
c
Just as some advice, you can usually just test things like this out yourself if you're not sure:
#include
using namespace std;
class parent {
protected:
int a;
public:
parent() : a(123) { cout << "in parent(): a == " << a << endl; };
};
class child : public parent {
int b;
public:
// question: is parent constructor done before init b?
child() : b(456), parent() { cout << "in child(): a == " << a << ", b == " << b << endl; };
};
int main() {
child c;
return 0;
}
prints
in parent(): a == 123
in child(): a == 123, b == 456