fork download
  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::endl;
  5.  
  6. class C {
  7. public:
  8. C() { cout << "Constructor of C called" << endl; }
  9.  
  10. ~C() { cout << "Donstructor of C called" << endl; }
  11. };
  12.  
  13. template <typename T>
  14. class A {
  15. public:
  16. A() { cout << "Constructor of A called" << endl; }
  17. ~A() { cout << "Destructor of A called" << endl; }
  18.  
  19. class B {
  20. public:
  21. B() { cout << "Constructor of A::B called" << endl; }
  22. ~B() { cout << "Destructor of A::B called" << endl; }
  23. };
  24. };
  25.  
  26. void TestFreeC() {
  27. cout << "TestFreeC:" << endl;
  28. C free_c;
  29. cout << endl;
  30. }
  31.  
  32. void TestFreeA() {
  33. cout << "TestFreeA:" << endl;
  34. A<C> free_a_for_free_c;
  35. cout << endl;
  36. }
  37.  
  38. void TestNotFreeB() {
  39. cout << "TestNotFreeB:" << endl;
  40. A<C>::B not_free_b_of_free_a_for_free_c;
  41. cout << endl;
  42. }
  43.  
  44. void TestFreeAForNotFreeB() {
  45. cout << "TestFreeAForNotFreeB:" << endl;
  46. A<A<C>::B> free_a_for_not_free_b_of_free_a_for_free_c;
  47. cout << endl;
  48. }
  49.  
  50. void GoingCrazy() {
  51. cout << "They are coming!: " << endl;
  52. A<A<A<A<A<C>::B>::B>::B>::B> strange_thing;
  53. cout << endl;
  54. }
  55.  
  56. int main() {
  57. TestFreeC();
  58. TestFreeA();
  59. TestNotFreeB();
  60. TestFreeAForNotFreeB();
  61. GoingCrazy();
  62. }
  63.  
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
TestFreeC:
Constructor of C called

Donstructor of C called
TestFreeA:
Constructor of A called

Destructor of A called
TestNotFreeB:
Constructor of A::B called

Destructor of A::B called
TestFreeAForNotFreeB:
Constructor of A called

Destructor of A called
They are coming!: 
Constructor of A called

Destructor of A called