title: In the following code how can I initialize a class member without using dummy values?
body: <p>// Example program</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;array&gt;
  
  class A{
      public:
          A(int tempY){
              y = tempY;
          }
          int y = 0;
  };
  
  class B{
      public:
          B(A tempZ){
              z = tempZ.y;
          }
          A z;
  
  };
  
  int main()
  {
      int x = 1;
      A objA(x);
      B objB(objA);
      std::cout &lt;&lt; "y = " &lt;&lt; objB.z &lt;&lt; "!\n";
  }
  </code></pre>
  
  <p>Build at:
  <a href="http://cpp.sh/3yj2" rel="nofollow">http://cpp.sh/3yj2</a></p>
  
  <p>There is an error in class B because I haven't passed a constructor parameter to member z.
  I don't want to initialize it with a dummy value, is there a way to only use constructor parameters to build member z, and how do I tell z to use B's constructor parameters?</p>
  
  <p>If I'm missing a fundamental aspect of C++ please let me know I'm just starting out.</p>