为什么我们需要使用virtual〜A()= default;而不是虚拟〜A(){}在C ++ 11? [英] Why do we need to use virtual ~A() = default; instead of virtual ~A() {} in C++11?
问题描述
在Stack Overflow post 在C ++ 11中检查对象类型 ,我有注释:
In Stack Overflow post Checking the object type in C++11, I have the comment:
在C ++ 11中,你实际上想要做
virtual〜A ;
什么是 virtual〜A()= default;
for?如何隐式移动构造函数丢失与 virtual〜A(){}
What is virtual ~A() = default;
for? How come implicit move constructors lost with virtual ~A() {}
?
推荐答案
评论不正确。
两者:
virtual ~A() = default;
和
virtual ~A() {}
。如果析构函数是用户声明的,则隐式移动成员被禁止。
are user declared. And the implicit move members are inhibited if the destructor is user declared.
[dcl.fct.def.default] / p4讨论用户声明的 >和用户提供的特殊成员:
[dcl.fct.def.default]/p4 discusses user-declared and user-provided special members:
em>如果是用户声明的,
在其第一个声明中未显式默认或删除。
A special member function is user-provided if it is user-declared and not explicitly defaulted or deleted on its first declaration.
这篇关于为什么我们需要使用virtual〜A()= default;而不是虚拟〜A(){}在C ++ 11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!