Advertisement
TwITe

Untitled

Dec 28th, 2017
82
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. using namespace std;
  3.  
  4. class Derived {
  5. public:
  6.     Derived() {
  7.         cout << "Derived constructor" << endl;
  8.     }
  9.  
  10.     ~Derived() {
  11.         cout << "Derived destructor" << endl;
  12.     }
  13. };
  14.  
  15. class Base {
  16. private:
  17.     int *a;
  18. public:
  19.     Base() {
  20.         Derived b;
  21.  
  22.         a = new int[100];
  23.  
  24.         throw runtime_error("error");
  25.     }
  26.  
  27.     ~Base() {
  28.         // delete[] a;
  29.     }
  30. };
  31.  
  32. int main() {
  33.     Base base;
  34.  
  35.     return 0;
  36. }
  37.  
  38. // Вывод:
  39. Derived constructor
  40. terminate called after throwing an instance of 'std::runtime_error'
  41.   what():  error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement