fork(1) download
  1. #include <iostream>
  2.  
  3. class A {
  4. public:
  5. A(){ std::cout << "A()\n"; }
  6. A(const A& a){ std::cout << "A(const A&)\n"; }
  7. ~A(){ std::cout << "~A()\n"; }
  8. void foo(){ std::cout << "A::foo()\n"; }
  9. };
  10.  
  11. class B : public A {
  12. public:
  13. B(){ std::cout << "B()\n"; }
  14. B(const B& b){ std::cout << "B(const B&)\n"; }
  15. B& operator=(const B& b){ std::cout << "B::operator=(const B&)\n"; return *this; }
  16. ~B(){ std::cout << "~B()\n"; }
  17. virtual void foo(){ std::cout << "B::foo()\n"; }
  18. };
  19.  
  20. class C : public B {
  21. public:
  22. C(){ std::cout << "C()\n"; }
  23. C& operator=(const C& c){ std::cout << "C::operator=(const C&)\n"; a_=c.a_; return *this; }
  24. ~C(){ std::cout << "~C()\n"; }
  25. void foo(){ std::cout << "C::foo()\n"; }
  26. protected:
  27. A a_;
  28. };
  29.  
  30. int main()
  31. {
  32. std::cout << "\tC c1:\n";
  33. C c1;
  34.  
  35. std::cout << "\n\n\tC c2(c1);\n";
  36. C c2(c1);
  37.  
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
	C c1:
A()
B()
A()
C()


	C c2(c1);
A()
B(const B&)
A(const A&)
~C()
~A()
~B()
~A()
~C()
~A()
~B()
~A()