title: How to call constructor of a nested class
body: <p>First off, I'm not talking about questions like these (<a href="https://stackoverflow.com/questions/9160267/how-to-initialise-constructor-of-a-nested-class-in-c">1</a>, <a href="https://stackoverflow.com/questions/23844715/nested-class-and-constructor-calling-understanding">2</a>). I'm talking about a class that already has a constructor and is only nested by value, not by definition...if that makes any sense.</p>
  
  <p>Currently, I have this methodology, which works, but uses <code>new</code> and is ugly IMO:</p>
  
  <pre><code>class A {
  private:
      int value;
  
  public:
      A(int _value);
  };
  
  class B {
  private:
      A *a;
  public:
      B(int _value);
  };
  </code></pre>
  
  <p>The constructor of B:</p>
  
  <pre><code>B::B(int _value)
  {
      a = new A(_value);
  }
  </code></pre>
  
  <p>If I were to change <code>A *a;</code> to <code>A a</code>, how would I create a <code>B</code> such that <code>A</code>'s constructor is called in the same way?</p>
  
  <p>I've tried:</p>
  
  <pre><code>B::B(int _value)
  {
      a = A(_value);    // no matching function for call to ‘A::A()’
      a = A::A(_value); // cannot call constructor ‘A::A’ directly
      a(_value);        // no match for call to ‘(A) (int&amp;)’
      a.A(_value);      // invalid use of `A::A`
  }
  </code></pre>
  
  <p>It doesn't seem possible without:</p>
  
  <ul>
  <li>using a pointer with <code>new</code></li>
  <li>using some explicit <code>void A::init(_value)</code> (would need an additional constructor for <code>A</code> to take no arguments)</li>
  <li>extending class A (would require changing specific private members to protected and would mesh their "namespaces" in an unwanted manner)</li>
  <li>questionable use of <code>memcpy()</code> (<code>A temp(_value); memcpy(&amp;a, &amp;temp, sizeof (A));</code>)</li>
  </ul>
  
  <p>Is this possible without resorting to the above methods?</p>