Advertisement
TwITe

Untitled

Dec 30th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <memory>
  3. using namespace std;
  4.  
  5. class A {
  6. public:
  7.     int* data;
  8.  
  9.     A(int* d) : data(d) {
  10.         try {
  11.             throw runtime_error("err");
  12.         }
  13.         catch (exception e) {
  14.             //delete data;
  15.         }
  16.     }
  17.  
  18.     ~A() {
  19.         cout << "A's destructor was called" << endl;
  20.     }
  21. };
  22.  
  23. class B {
  24. public:
  25.     int* data2;
  26.     A* a;
  27.  
  28.     B() : data2(new int[10]), a(new A(new int[2])) {}
  29.  
  30.     ~B() {
  31.         cout << "B's destructor was called" << endl;
  32.         //delete a;
  33.     }
  34. };
  35.  
  36. int main() {
  37.     try {
  38.         B b();
  39.     }
  40.     catch (exception e) {
  41.         cout << "EXCEPTION SUCK";
  42.         throw runtime_error("error");
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement