hackingcpp / comments

Comments regarding hackingcpp.com
0 stars 0 forks source link

cpp/lang/destructors #18

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

C++ Destructors and RAII | hacking C++

Destructors - one of the most important language constructs of C++ - allow to tie resource management to an object's lifetime (also known as RAII).

https://hackingcpp.com/cpp/lang/destructors.html

yqj238 commented 2 years ago

Hi Andre,

Thank you for this beautiful website and the great wealth of resource it contains. I can't believe I didn't find it sooner.

In the Execution Order on Destruction section, it was written that the data members are destroyed in the order of declaration. However, some sources (e.g. Visual Studio Documentation and cppreference) state that the destruction sequence is in the reverse order of declaration. Could you verify this discrepancy please?

Many thanks!

Yiqing

hackingcpp commented 2 years ago

@yqj238 谢谢你 for spotting this - you're right, members are destroyed in reverse declaration order; I fixed the corresponding section. For the members of a stack-allocated object it is obvious: they will be popped from the stack (just like local variables of a function) so the last allocated member will be destroyed first.