什么是C ++中的非平凡析构函数? [英] What is a non-trivial destructor in C++?
问题描述
我在阅读这,
一个类有一个非平凡的析构函数,如果它有一个明确的
定义析构函数,或者如果它有一个成员对象或一个基类,
有一个非平凡的析构函数。
A class has a non-trivial destructor if it either has an explicitly defined destructor, or if it has a member object or a base class that has a non-trivial destructor.
,我有一个类,
class C {
public:
~C(); // not explicitly declared.
};
如果 C ::〜C()
推荐答案
你会得到你的话混在一起。您的示例确实声明了一个显式析构函数。
You are getting your words mixed up. Your example does indeed declare an explicit destructor. You just forget to define it, too, so you'll get a linker error.
这个规则非常简单:你的类有明确的析构函数?如果是,你是不平凡的。如果不是,则检查每个非静态成员对象;如果任何 是不重要的,那么你是不平凡的。
The rule is very straight-forward: Does your class have an explicit destructor? If yes, you're non-trivial. If no, check each non-static member object; if any of them are non-trivial, then you're non-trivial.
这篇关于什么是C ++中的非平凡析构函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!