add object lifetime example

master
neingeist 11 years ago
parent 51f5a4c8ed
commit 94de91cd85

1
.gitignore vendored

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

@ -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)

@ -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.
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Loading…
Cancel
Save