How to call copy constructor of all base classes for copying most derived class object in diamond inheritance in C++?
Consider the below code: #include<iostream> using namespace std; class A { public: A() {cout << "1";} A(const A &obj) {cout << "2";} }; class B: virtual A { public: B() {cout << "3";} B(const B & obj) {cout<< "4";} }; class C: virtual A { public: C() {cout << "5";} C(const C & obj) {cout << "6";} }; class D:B,C { public: D() {cout << "7";} D(const D & obj) {cout << "8";} }; int main() { D d1; cout << "\n"; D d(d1); } The output of the program is below: 1357 1358 So, for line D d(d1) the copy constructor of D class is bein called. During inheritance we need to explicitly call copy constructor