class - Where C++ calls destructors? -
assuming member
, mylist
2 user defined classes. in following code:
void filllist(mylist &list1) { member m1("aaa"); member m2("bbb"); list1.insert(m1); list1.insert(m2); } void func1() { mylist lst; filllist(lst); lst.printall(); } int main() { func1(); return 0; }
at point c++ call destructor of each m1
, m2
, lst
?
is safe assume c++ not remove object used again?
at point c++ call destructor of each m1, m2 , lst?
the destructors called @ end of scope, in reverse order of objects definitions. in case, func1()
first called, defines lst
, calls filllist()
, defines m1
, m2
. next filllist()
ends, m2
m1
destructors called (in reverse order of declaration). func1()
ends, lst
destructor called.
is safe assume c++ not remove object used again?
i don't understand mean. destructed object gone, cannot use anymore. trying access (via dangling pointer/reference) undefined behaviour.
Comments
Post a Comment