Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- senchev@senchev-yoga:~/scratch$ cat test.cpp
- #include <iostream>
- class Foo {
- public:
- Foo() { std::cout << "Constructing Foo: " << this << std::endl; }
- ~Foo() { std::cout << "Destructing Foo: " << this << std::endl; }
- int value;
- };
- class Bar {
- public:
- Bar() { std::cout << "Constructing Bar: " << this << std::endl; }
- ~Bar() { std::cout << "Destructing Bar: " << this << std::endl; }
- Foo foo;
- };
- class Baz {
- public:
- Baz() {
- std::cout << "Constructing Baz: " << this << std::endl;
- bar = new Bar();
- }
- ~Baz() {
- std::cout << "Destructing Baz: " << this << std::endl;
- delete bar;
- }
- Bar *bar;
- Foo foo;
- };
- int main(void) {
- std::cout << "1" << std::endl;
- Foo foo{};
- std::cout << "2" << std::endl;
- Bar *bar = new Bar();
- std::cout << "3" << std::endl;
- Baz baz{};
- std::cout << "4" << std::endl;
- delete bar;
- std::cout << "5" << std::endl;
- return 0;
- }
- senchev@senchev-yoga:~/scratch$ g++ test.cpp -o test
- senchev@senchev-yoga:~/scratch$ ./test
- 1
- Constructing Foo: 0x7fff484236b4
- 2
- Constructing Foo: 0x5639eed3c2c0
- Constructing Bar: 0x5639eed3c2c0
- 3
- Constructing Foo: 0x7fff484236c8
- Constructing Baz: 0x7fff484236c0
- Constructing Foo: 0x5639eed3c2e0
- Constructing Bar: 0x5639eed3c2e0
- 4
- Destructing Bar: 0x5639eed3c2c0
- Destructing Foo: 0x5639eed3c2c0
- 5
- Destructing Baz: 0x7fff484236c0
- Destructing Bar: 0x5639eed3c2e0
- Destructing Foo: 0x5639eed3c2e0
- Destructing Foo: 0x7fff484236c8
- Destructing Foo: 0x7fff484236b4
- senchev@senchev-yoga:~/scratch$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement