Usage of “this” in destructor

扶醉桌前 提交于 2019-12-28 21:49:14

问题


Is it valid to call some function in destructor with this argument? Function does not store pointer, but assume full-functional object.


回答1:


this is still valid in the destructor.

However, you need bear in mind that virtual functions no longer work properly as you might expect once the object is being destroyed; see e.g. Never Call Virtual Functions during Construction or Destruction. Essentially, the dynamic type of the object is modified as each destructor completes.




回答2:


In one word: YES.
It's fully valid to use this in the D`TOR



来源:https://stackoverflow.com/questions/10979250/usage-of-this-in-destructor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!