diff --git a/.gitignore b/.gitignore index 1c58de3..82559fa 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ unique_ptr list-initializers array-bounds accumulate +object-lifetime diff --git a/CMakeLists.txt b/CMakeLists.txt index d1dec41..f059ef7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/object-lifetime.cpp b/object-lifetime.cpp new file mode 100644 index 0000000..ec0bef5 --- /dev/null +++ b/object-lifetime.cpp @@ -0,0 +1,25 @@ +#include + +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. +} diff --git a/object-lifetime.png b/object-lifetime.png new file mode 100644 index 0000000..8fdd6cb Binary files /dev/null and b/object-lifetime.png differ