title: C++ class composition,why constructor not called?
body: <p>I have the following code and i don't understand, why at the creation of object b, the constructor of class A doesn't called.......I will appreciate a little help.hank you very much.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class MyClass
  {
      int x;
  public:
      MyClass(int y);                           
      MyClass(MyClass &amp;my) 
      {
          x = my.x;
          cout &lt;&lt; "My class created by copy" &lt;&lt; endl;
      }
  };
  MyClass::MyClass(int y)
  {
      x = y;
      cout &lt;&lt; "My class created" &lt;&lt; endl;
  }
  
  class A {
      MyClass k;
      public:
          A(MyClass &amp;my) : k(my) {
              cout &lt;&lt; "A created" &lt;&lt; endl;
          }
  };
  class B {
      A data;
      public:
          B(A&amp; aa) : data(aa)
          {
              cout &lt;&lt; "B created" &lt;&lt; endl;
          }
  };
  int main()
  {
      MyClass obj(100);
      A a(obj);
      B b(a);                     
      return 0;
  }
  </code></pre>
  
  <hr>
  
  <p>execution:</p>
  
  <pre><code>My class created
  My class created by copy
  A created
  My Class created by copy
  B created
  </code></pre>