默认的默认构造函数 ?在n3290草案中
n3290 草案 §12.1(构造函数)中的一点 ¶5:
隐式声明的默认构造函数是以下对象的
内联公共
成员: 它的阶级。类X
的默认默认构造函数被定义为已删除 如果:
X
是一个类似联合的类,它有一个带有非平凡成员的变体成员 默认构造函数,- 任何没有大括号或等号初始化器的非静态数据成员都是 引用类型,
- const 限定类型(或数组)的任何非变体非静态数据成员 其中)没有大括号或等于初始化器没有用户提供的 默认构造函数,
X
是一个联合体,其所有变体成员都是 const 限定类型 (或其数组),X
是一个非联合类,任何匿名联合成员的所有成员都是 const 限定类型(或其数组),- 任何直接或虚拟基类,或不带任何内容的非静态数据成员 大括号或等于初始化器,具有类类型
M
(或其数组)并且M
没有应用默认构造函数或重载解析 (13.3)M
的默认构造函数会导致歧义或导致函数 从默认的默认构造函数中删除或无法访问,或者- 任何直接或虚拟基类或非静态数据成员都具有带有
的类型 已从默认的默认构造函数中删除或无法访问的析构函数
请用一些示例程序解释默认的默认构造函数。
A point from n3290 draft §12.1 (Constructors) ¶5:
An implicitly-declared default constructor is an
inline public
member of
its class. A defaulted default constructor for classX
is defined as deleted
if:
X
is a union-like class that has a variant member with a non-trivial
default constructor,- any non-static data member with no brace-or-equal-initializer is of
reference type,- any non-variant non-static data member of const-qualified type (or array
thereof) with no brace-or-equal-initializer does not have a user-provided
default constructor,X
is a union and all of its variant members are of const-qualified type
(or array thereof),X
is a non-union class and all members of any anonymous union member are of
const-qualified type (or array thereof),- any direct or virtual base class, or non-static data member with no
brace-or-equal-initializer, has class typeM
(or array thereof) and eitherM
has no default constructor or overload resolution (13.3) as applied
toM
’s default constructor results in an ambiguity or in a function that is
deleted or inaccessible from the defaulted default constructor, or- any direct or virtual base class or non-static data member has a type with a
destructor that is deleted or inaccessible from the defaulted default constructor
Please explain the defaulted default constructor with some example program.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为此摘自维基百科解释this:
显式默认和删除的特殊成员函数
代码示例:
由于您似乎是 Standerdese 粉丝(几乎所有问题都寻求标准引用的解释)本文介绍了标准提交如何定义默认值和删除的函数应该值得您阅读:
默认和删除的函数
I think this excerpt from Wikipedia explains this:
Explicitly-defaulted and deleted special member functions
Code Example:
Since you seem to be a Standerdese fan(Almost all of your Questions seek explanations on Standard Quotes) this paper here about how standards committe arrive to defining default and deleted functions should be a good read for you:
Defaulted and Deleted Functions
如果使用
= default;
语法声明特殊成员函数之一,则该函数是“默认的”。您引用的第一行之前的行指出:因此,“默认”默认构造函数是使用
= default
声明的默认构造函数(可以不带参数调用的构造函数)。这可以使用= default
语法显式定义,也可以根据上面的行隐式定义。One of the special member functions is "defaulted" if it is declared with the
= default;
syntax. The line right before the first line you quoted states:Therefore, a "defaulted" default constructor is a default constructor (constructor that can be called with no arguments) that is declared with
= default
. This can be explicitly defined using the= default
syntax, or implicitly defined, per the above line.