Hello everyone,
I am wondering in the following code, member variable a in class B is not put in the initialization list or constructor of B directly, but it is initialized. How and when member variable a of class B is created and initialized? Is constructor of B invokes constructor of a?
Output is,
In constructor A
In constructor B
Code:#include <iostream> using namespace std; class A { public: A() { cout << "In constructor A" << endl; } }; class B { public: A a; B() { cout << "In constructor B" << endl; } }; int main() { B b; return 0; }
thanks in advance,
George