什么时候不应该使用虚拟析构函数? [英] When should you not use virtual destructors?
本文介绍了什么时候不应该使用虚拟析构函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有很好的理由不是为类声明一个虚拟析构函数?什么时候应该避免写一个?
Is there ever a good reason to not declare a virtual destructor for a class? When should you specifically avoid writing one?
推荐答案
当下面的任何一个为真时,不需要使用虚拟析构函数:
There is no need to use a virtual destructor when any of the below is true:
- 无意从中派生类
- 无法在堆上实例化
- 不打算存储在超类的指针中
没有具体的原因来避免它,除非你真的按下内存。
No specific reason to avoid it unless you are really so pressed for memory.
这篇关于什么时候不应该使用虚拟析构函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文