Advertisement
TwITe

Untitled

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