Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <memory>
- using namespace std;
- class Moo {
- private:
- int mNumber;
- public:
- Moo() : mNumber( 123 ) {
- cout << mNumber << endl;
- };
- ~Moo() {
- cout << "~Moo" << endl;
- }
- };
- class Foo {
- private:
- unique_ptr<Moo> mMoo;
- public:
- Foo() {
- mMoo = std::move( unique_ptr<Moo>( new Moo ));
- cout << "Foo()" << endl;
- }
- ~Foo() {
- cout << "~Foo()" << endl;
- }
- };
- class Bar {
- private:
- Foo foo;
- public:
- Bar(){
- throw std::runtime_error( "Bar exception" );
- cout << "Bar()" << endl;
- }
- ~Bar() {
- cout << "~Bar()" << endl;
- }
- };
- void main() {
- try {
- Bar bar;
- } catch( std::runtime_error err ) {
- cout << err.what() << endl;
- }
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment