title: When will C++ call the constructor on an object that is a class member?
body: <p>let's say I have a class</p>
  
  <pre><code>class MyClass {
      public:
          AnotherClass myObject;
  };
  </code></pre>
  
  <p>My issue is that I want to initialize myObject with arguments to it's constructor, exactly if I were declaring it on the stack during a function</p>
  
  <pre><code>AnotherClass myObject(1, 2, 3);
  </code></pre>
  
  <p>but I want to do this for the class member in the constructor:</p>
  
  <pre><code>MyClass::MyClass() {
      myObject = ...?
      ...
  }
  </code></pre>
  
  <p>The problem is exactly that. If I declare a class member that has a constructor, will C++ call the default constructor? How can I still declare the variable in the class definition but initialize it in the constructor?</p>
  
  <p>Thanks for any answers!</p>