add object lifetime example
This commit is contained in:
parent
51f5a4c8ed
commit
94de91cd85
4 changed files with 27 additions and 0 deletions
1
.gitignore
vendored
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)
|
||||
|
|
25
object-lifetime.cpp
Normal file
25
object-lifetime.cpp
Normal 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
BIN
object-lifetime.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 72 KiB |
Loading…
Add table
Add a link
Reference in a new issue