Order of execution in class initialization

Hi all,

If i have this

header:

class MyClass
{
 public:
      MyClass(char* someString, AnimalObject& value);

private:
     void  SomeMethod();
etc...

AnimalObject& a;
DogObject & d;

};

Implementation:

MyClass::MyClass(char* somestring, AnimalObject& value): a(somestring,value), d(a)

my question is:
can a(somestring,value) always get executed first then d(a).  Or there is total depending on the compiler

Thx

 



Answer this question

Order of execution in class initialization

  • Nalpam

    The order of execution in the inialization list depends on the declaration order.

    You declare a first, so a(somestring,value) will always get executed before d(a).


  • Order of execution in class initialization