fork download
  1. #include <stdio.h>
  2.  
  3.  
  4. class Ana
  5.  
  6. {
  7. int x;
  8.  
  9. public:
  10.  
  11. Ana(int c);
  12.  
  13. ~Ana() {}
  14.  
  15. int ghf() const {return x;}
  16.  
  17. class A
  18.  
  19. {
  20.  
  21. public:
  22.  
  23. A() {printf("\nKONSTRUKTOR A %p\n",this);}
  24.  
  25. A(const A & rhs) {printf("\nKONSTRUKTOR A copy %p %p\n",this,& rhs);}
  26.  
  27. ~A() {printf("\nDESTRUKTOR A %p\n",this);}
  28. };
  29.  
  30. class B : public A
  31.  
  32. {
  33.  
  34. public:
  35.  
  36. B() {printf("\nKONSTRUKTOR B %p\n",this);}
  37.  
  38. B(const B & rhs) {printf("\nKONSTRUKTOR B copy %p %p\n",this,& rhs);}
  39.  
  40. ~B() {printf("\nDESTRUKTOR B %p\n",this);}
  41. };
  42.  
  43. class C : public B
  44.  
  45. {
  46.  
  47. public:
  48.  
  49. C() {printf("\nKONSTRUKTOR C %p\n",this);}
  50.  
  51. C(const C & rhs) {printf("\nKONSTRUKTOR C copy %p %p\n",this,& rhs);}
  52.  
  53. ~C() {printf("\nDESTRUKTOR C %p\n",this);}
  54. };
  55. };
  56.  
  57. Ana :: Ana(int c) :
  58.  
  59. x(c)
  60.  
  61. {
  62. if(c == 0) throw B();
  63.  
  64. if(c < 0) throw A();
  65.  
  66. if(c > 10) throw C();
  67. }
  68.  
  69. int main()
  70.  
  71. {
  72. try
  73.  
  74. {
  75. Ana s(11);
  76.  
  77. printf("\n-------- %d\n",s.ghf());
  78. }
  79.  
  80.  
  81. catch (Ana :: C )
  82.  
  83. {
  84. printf("\n****** c > 10\n");
  85. }
  86.  
  87. catch (Ana :: B )
  88.  
  89. {
  90. printf("\n****** c == 0\n");
  91. }
  92.  
  93.  
  94. catch (Ana :: A )
  95.  
  96. {
  97. printf("\n****** c < 0\n");
  98. }
  99.  
  100.  
  101.  
  102.  
  103. return 0;
  104. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
KONSTRUKTOR A 0x91ed068

KONSTRUKTOR B 0x91ed068

KONSTRUKTOR C 0x91ed068

KONSTRUKTOR A 0xbff65bdc

KONSTRUKTOR B 0xbff65bdc

KONSTRUKTOR C copy 0xbff65bdc 0x91ed068

****** c > 10

DESTRUKTOR C 0xbff65bdc

DESTRUKTOR B 0xbff65bdc

DESTRUKTOR A 0xbff65bdc

DESTRUKTOR C 0x91ed068

DESTRUKTOR B 0x91ed068

DESTRUKTOR A 0x91ed068