TwITe

Untitled

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