“这个”的使用在析构函数中 [英] Usage of "this" in destructor

查看:142
本文介绍了“这个”的使用在析构函数中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 this 参数调用析构函数中的一些函数是否有效?
函数不存储指针,但假设是全功能对象。

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

推荐答案

/ code>在析构函数中仍然有效。

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.

这篇关于“这个”的使用在析构函数中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆