While the initialization in your example does happen in the order you want, it's not for the reason you assume: Initialization happens in the order of the data members declaration in the class definition. The reason for this is that the destructor must destroy the members in backward order not matter which constructor was used to create the object. For that, a constructor-independent way of defining the construction order must be used.
That means that, if instead of
class myClass
{
private:
...
int m_nDataLength;
boost::shared_array<int> m_pData;
someone would change your code to
class myClass
{
private:
...
boost::shared_array<int> m_pData;
int m_nDataLength;
then the code would have a bug.
My advice is:
- Write your constructors so that the initialiszation order doesn't matter.
- If you cannot do this (note: to me this happened less than 5 times in the last decade), make it completely clear at the point the data members are declared.
Something like this should do:
class myClass
{
private:
...
int m_nDataLength; // Note: Declaration order
boost::shared_array<int> m_pData; // matters here!