Members are initialized in the order they are declared. So mText will be initialized first, then mFont, mWindow, mClock, mTime, mString, in that order.
#include <iostream>
using std::cerr;
struct A {
A(){ cerr << "A()\n"; }
A(A& a){ cerr << "A(A& a)\n"; }
~A(){ cerr << "~A()\n"; }
};
struct B {
B(){ cerr << "B()\n"; }
~B(){ cerr << "~B()\n"; }
};
struct C {
C(){ cerr << "C()\n"; }
~C(){ cerr << "~C()\n"; }
};
struct Test {
// This order destines in which order the objects will get constructed
// and destructed (destruction order is their reverse order of
// the construction order).
A objAA;
A objA;
B objB;
C objC;
// This order doesn't influence the construction/destruction order.
Test() : objC(), objB(), objAA(objA), objA(){}
};
int main ()
{
Test testobj;
}
Sorry for my last question, at the online compiler were the compiler warnings (per default) disabled. Enabling them throws the warning that objA will be passed uninitialized to objA.
test.cpp: In constructor ‘Test::Test()’:
test.cpp:25:7: warning: ‘Test::objC’ will be initialized after [-Wreorder]
C objC;
^~~~
test.cpp:24:7: warning: ‘B Test::objB’ [-Wreorder]
B objB;
^~~~
test.cpp:27:5: warning: when initialized here [-Wreorder]
Test() : objC(), objB(), objAA(objA), objA(){}
^~~~
test.cpp:24:7: warning: ‘Test::objB’ will be initialized after [-Wreorder]
B objB;
^~~~
test.cpp:22:7: warning: ‘A Test::objAA’ [-Wreorder]
A objAA;
^~~~~
test.cpp:27:5: warning: when initialized here [-Wreorder]
Test() : objC(), objB(), objAA(objA), objA(){}
^~~~