title: How to call copy constructor of all base classes for copying most derived class object in diamond inheritance in C++?
body: <p>Consider the below code:</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  class A
  {
  public:
       A() {cout &lt;&lt; "1";}
       A(const A &amp;obj) {cout &lt;&lt; "2";}
  };
  
  class B: virtual A
  {
  public:
      B() {cout &lt;&lt; "3";}
      B(const B &amp; obj) {cout&lt;&lt; "4";}
  };
  
  class C: virtual A
  {
  public:
     C() {cout &lt;&lt; "5";}
     C(const C &amp; obj) {cout &lt;&lt; "6";}
  };
  
  class D:B,C
  {
  public:
      D()  {cout &lt;&lt; "7";}
      D(const D &amp; obj) {cout &lt;&lt; "8";}
  };
  
  int main()
  {
     D d1;
     cout &lt;&lt; "\n";
     D d(d1);
  }
  </code></pre>
  
  <p>The output of the program is below:</p>
  
  <pre><code>1357
  1358
  </code></pre>
  
  <p>So, for line <code>D d(d1)</code> the copy constructor of <code>D</code> class is bein called. During inheritance we need to explicitly call copy constructor of base class otherwise only default constructor of base class is called. I understood till here.</p>
  
  <p><strong>My Problem:</strong></p>
  
  <p>Now I want to call copy constructor of all base classes during <code>D d(d1)</code> execution. For that if I try below
  <code>D(const D &amp; obj) : A(obj), B(obj), C(obj) {cout &lt;&lt; "8";}</code>
  Then I get this error:
  error: <code>'class A A::A' is inaccessible within this context</code></p>
  
  <p>How to resolve the issue. I want copy constructor of <code>A</code>, <code>B</code> and <code>C</code> when copy constructor of <code>D</code> gets called. It might be very small change but I am not getting. </p>