mrDIMAS

test

Dec 19th, 2015
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <memory>
  4.  
  5. using namespace std;
  6.  
  7. class Moo {
  8. private:
  9.     int mNumber;
  10. public:
  11.     Moo() : mNumber( 123 ) {
  12.         cout << mNumber << endl;
  13.     };
  14.  
  15.     ~Moo() {
  16.         cout << "~Moo" << endl;
  17.     }
  18. };
  19.  
  20. class Foo {
  21. private:
  22.     unique_ptr<Moo> mMoo;
  23. public:
  24.     Foo() {
  25.         mMoo = std::move( unique_ptr<Moo>( new Moo ));
  26.         cout << "Foo()" << endl;
  27.     }
  28.     ~Foo() {
  29.         cout << "~Foo()" << endl;
  30.     }
  31. };
  32.  
  33. class Bar {
  34. private:
  35.     Foo foo;
  36. public:
  37.     Bar(){
  38.         throw std::runtime_error( "Bar exception" );
  39.         cout << "Bar()" << endl;
  40.     }
  41.  
  42.     ~Bar() {
  43.         cout << "~Bar()" << endl;
  44.     }
  45. };
  46.  
  47.  
  48. void main() {
  49.     try {
  50.         Bar bar;
  51.     } catch( std::runtime_error err ) {
  52.         cout << err.what() << endl;
  53.     }
  54.     _getch();
  55. }
Advertisement
Add Comment
Please, Sign In to add comment