title: C++ Default Constructor Called
body: <p>In the code below, class B has a member that is of type class A (varA1).  I want to create a class B object where the member varA1 is intended to use the non-default constructor A(int v1) in class A.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using std::cout; using std::endl; using std::string;
  
  class A {
  public:
      A() { cout &lt;&lt; "A default constructor" &lt;&lt; endl;}
      A(int v1);
  private:
      int var1;
  };
  A::A(int v1) {
      cout &lt;&lt; "A int constructor" &lt;&lt; endl;
      var1 = v1;
  }
  
  class B {
  public:
      B() { cout &lt;&lt; "B default constructor" &lt;&lt; endl;}
      B(int v1);
  private:
      int var1;
      A varA1;
  };
  B::B(int v1) {
      cout &lt;&lt; "B int constructor" &lt;&lt; endl;
      var1 = v1;
      A varA1(int v1);
  }
  
  int main()
  {
      A TestA(1);
      B TestB(1);
  
      return 0;
  }
  </code></pre>
  
  <p>However when I run the code above I get the following output:</p>
  
  <pre><code>A int constructor
  A default constructor
  B int constructor
  </code></pre>
  
  <p>I must be doing some wrong here.  What do I need to change so that the B class uses the non-default constructor A(int v1) in class A?</p>
  
  <p>I am using ubuntu 14.04LTS.  Both GNU G++ 4.9 and 5.1 gave the same results.</p>
  
  <p>Thanks in advance for reading and answering.</p>