add object lifetime example
parent
51f5a4c8ed
commit
94de91cd85
@ -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…
Reference in New Issue