add object lifetime example

This commit is contained in:
neingeist 2014-04-13 10:12:03 +02:00
parent 51f5a4c8ed
commit 94de91cd85
4 changed files with 27 additions and 0 deletions

1
.gitignore vendored
View file

@ -11,3 +11,4 @@ unique_ptr
list-initializers
array-bounds
accumulate
object-lifetime

View file

@ -11,3 +11,4 @@ add_executable(unique_ptr unique_ptr.cpp)
add_executable(list-initializers list-initializers.cpp)
add_executable(array-bounds array-bounds.cpp)
add_executable(accumulate accumulate.cpp)
add_executable(object-lifetime object-lifetime.cpp)

25
object-lifetime.cpp Normal file
View file

@ -0,0 +1,25 @@
#include <cstdio>
struct A {
A() { puts("A()"); }
~A() { puts("~A()"); }
};
struct B {
B() { puts("B()"); }
~B() { puts("~B()"); }
};
struct C {
A a;
B b;
C() { puts("C()"); }
~C() { puts("~C()"); }
};
int main() {
C c;
// Destructors should be called in exactly the opposite order of the
// constructor calls.
}

BIN
object-lifetime.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB