fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Base
  5. {
  6. public:
  7. Base()
  8. {
  9. cout << "Base()\n";
  10. }
  11.  
  12. Base(int)
  13. {
  14. cout << "Base(int)\n";
  15. }
  16.  
  17. ~Base()
  18. {
  19. cout << "~Base()\n";
  20. }
  21.  
  22. Base& operator=(int)
  23. {
  24. cout << "Base::operator=(int)\n";
  25. return *this;
  26. }
  27. };
  28.  
  29. class Derived : public Base
  30. {
  31. public:
  32. Derived()
  33. {
  34. cout << "Derived()\n";
  35. }
  36.  
  37. Derived(int n) : Base(n)
  38. {
  39. cout << "Derived(int)\n";
  40. }
  41.  
  42. ~Derived()
  43. {
  44. cout << "~Derived()\n";
  45. }
  46. };
  47.  
  48. class Holder
  49. {
  50. public:
  51. Holder(int n)
  52. {
  53. member = n;
  54. }
  55.  
  56. Derived member;
  57. };
  58.  
  59. int main(int argc, char* argv[])
  60. {
  61. cout << "Start\n";
  62. Holder obj(1);
  63. cout << "Finish\n";
  64.  
  65. return 0;
  66. }
  67.  
Success #stdin #stdout 0.01s 2724KB
stdin
Standard input is empty
stdout
Start
Base()
Derived()
Base(int)
Derived(int)
~Derived()
~Base()
Finish
~Derived()
~Base()