title: Can I initialize an object in the initialization list with another class member?
body: <p>Haven't found quite this problem in the site. So say I have two classes, one which holds a reference to the other:</p>
  
  <pre><code>class ClassA {};
  
  class ClassB
  {
      classA &amp; r_classA;
      public:
          ClassB( ClassA &amp; io_classA ):r_classA( io_classA ){}
  };
  </code></pre>
  
  <p>So, if I want to create an instance of ClassB, i have to pass it a reference to classA in the constructor:</p>
  
  <pre><code>int main()
  {
      ClassA classA;
      ClassB classB ( classA );
      return 0;
  }
  </code></pre>
  
  <p>Now say I create a class ClassC that holds these two:</p>
  
  <pre><code>class ClassC
  {
      ClassA m_classA;
      ClassB m_classB;
      public:
          ClassC();
  }
  </code></pre>
  
  <p>My question is, can I count on m_classA being created before m_classB is constructed in the initialization list? That is to say, can I do this:</p>
  
  <pre><code>ClassC::ClassC()
  : m_classA()
  , m_classB( m_classA )
  {}
  </code></pre>
  
  <p>Is this standards compliant? Portable? Do I need to take any special precautions? I'm declaring m_classA before m_classB in the body of ClassC already, and the compiler didn't throw any warnings. The program seems to work ok. I just want to check that I'm not counting on some unreliable behavior that'll cause a crash or weird bugs down the line.</p>