fork(2) download
  1. #include <iostream>
  2.  
  3. struct A
  4. {
  5. A(){ std::cout << "A default ctor" << std::endl; }
  6. A(A const&){ std::cout << "A copy ctor" << std::endl; }
  7. virtual ~A() = 0;
  8. }; A::~A(){}
  9.  
  10. struct B : virtual A
  11. {
  12. B(){ std::cout << "B default ctor" << std::endl; }
  13. B(B const&o) : A(o) { std::cout << "B copy ctor" << std::endl; }
  14. virtual ~B() = 0;
  15. }; B::~B(){}
  16. struct C : virtual A
  17. {
  18. C(){ std::cout << "C default ctor" << std::endl; }
  19. C(C const&o) : A(o) { std::cout << "C copy ctor" << std::endl; }
  20. virtual ~C() = 0;
  21. }; C::~C(){}
  22.  
  23. struct D : B, C
  24. {
  25. D(){ std::cout << "D default ctor" << std::endl; }
  26. D(D const&o) : A(o), B(o), C(o) { std::cout << "D copy ctor" << std::endl; }
  27. virtual ~D() = 0;
  28. }; D::~D(){}
  29.  
  30. struct E : D
  31. {
  32. E(){ std::cout << "E default ctor" << std::endl; }
  33. E(E const&o) : A(o), D(o) { std::cout << "E copy ctor" << std::endl; }
  34. virtual ~E(){}
  35. };
  36.  
  37. int main()
  38. {
  39. E e;
  40. std::cout << std::endl << std::endl;
  41. E e2(e);
  42. }
  43.  
Success #stdin #stdout 0s 2856KB
stdin
Standard input is empty
stdout
A default ctor
B default ctor
C default ctor
D default ctor
E default ctor


A copy ctor
B copy ctor
C copy ctor
D copy ctor
E copy ctor