Advertisement
TwITe

Untitled

Dec 30th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 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(int* s) : data2(s), a(new A(new int(2))) {}
  29.  
  30.     ~B() {
  31.         cout << "B's destructor was called" << endl;
  32.         delete a;
  33.     }
  34. };
  35.  
  36. class C {
  37.  
  38. };
  39.  
  40. int main() {
  41.     try {
  42.         int arr[] = {1, 2, 3};
  43.         B b(arr);
  44.     }
  45.     catch (exception e) {
  46.         cout << "EXCEPTION SUCK";
  47.         throw runtime_error("error");
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement