考虑以下代码:
#include <iostream>
class Test
{
public:
constexpr Test(const int x) : _x(x) {}
constexpr int get() const {return _x;}
~Test() {} // HERE
protected:
const int _x;
};
int main()
{
static constexpr Test test(5);
return 0;
}
如果我删除HERE
代码编译良好的行,但如果我定义一个空的析构函数,它会导致编译错误,说它Test
是非文字的。
为什么空析构函数和根本没有析构函数之间有什么区别?
编辑:另一个相关问题:如果空和文字析构函数不同,如何定义受保护的文字析构函数?