the first one is for " ok " object i get that , the second is for lets object , and the third is for the date object inside people's class , but what about the 4th ?
Line 38: You're passing birthday by value. A temporary instance gets constructed on the stack, then destructed when you're done calling lets' constructor at line 61.
oh , I forgot about the last in first out , so the birthday object inside of people gets destroyed first then the " lets " object , then the ok object , but the last one ?
An object which is contained by another object must be constructed before the containing object is finished being constructed and must be destructed before the containing object is finished being destructed.
#include <iostream>
struct A
{
A() { std::cout << this << " constructed via A()\n"; }
A(const A&) { std::cout << this << " constructed via A(const A&)\n"; }
~A() { std::cout << this << " destructed via ~A()\n"; }
};
struct B
{
A a;
B(const A& a)
: a(a) { std::cout << this << " constructed via B(const A&)\n"; }
~B() { std::cout << this << " destructed via ~B()\n"; }
};
int main()
{
A a;
B b(a);
}