fork download
  1. #include <iostream>
  2.  
  3. struct A {
  4. A() { std::cout << "A()" << std::endl; }
  5. };
  6.  
  7. struct B : A {
  8. B() { std::cout << "B()" << std::endl; }
  9. B(const B& b) { std::cout << "B(const B& b)" << std::endl; }
  10. };
  11.  
  12. struct C : A {
  13. C() { std::cout << "C()" << std::endl; }
  14. C(const C& c) : A(c) { std::cout << "C(const C& c)" << std::endl; }
  15. };
  16.  
  17. int main() {
  18. std::cout << "Construct b1" << std::endl;
  19. B b1;
  20. std::cout << std::endl << "Construct b2" << std::endl;
  21. B b2(b1);
  22.  
  23. std::cout << std::endl << "Construct c1" << std::endl;
  24. C c1;
  25. std::cout << std::endl << "Construct c2" << std::endl;
  26. C c2(c1);
  27. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Construct b1
A()
B()

Construct b2
A()
B(const B& b)

Construct c1
A()
C()

Construct c2
C(const C& c)