加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c中构造函数的默认访问权限是什么

发布时间:2020-12-16 10:44:25 所属栏目:百科 来源:网络整理
导读:c中构造函数的默认访问权限是什么?为什么? 公共,私人还是受保护? 我如何通过代码检查它? 解决方法 如果您没有自己声明构造函数,编译器将始终为您生成一个简单的公共构造函数.它们还将隐式创建公共副本构造函数和副本赋值运算符. 从c标准12.1.5: If ther
c中构造函数的默认访问权限是什么?为什么?

公共,私人还是受保护?

我如何通过代码检查它?

解决方法

如果您没有自己声明构造函数,编译器将始终为您生成一个简单的公共构造函数.它们还将隐式创建公共副本构造函数和副本赋值运算符.

从c标准12.1.5:

If there is no user-declared constructor for class X,a constructor having no parameters is implicitly declared as defaulted. An implicitly-declared default constructor is an inline public member of its class.

12.8.7和12.8.11:

If the class definition does not explicitly declare a copy constructor,one is declared implicitly. […]
An implicitly-declared copy/move constructor is an inline public member of its class.

最后12.8.18,12.8.20,12.8.22:

If the class definition does not explicitly declare a copy assignment operator,one is declared implicitly. […]
If the definition of a class X does not explicitly declare a move assignment operator,one will be implicitly declared […].
An implicitly-declared copy/move assignment operator is an inline public member of its class.

如果您使用的是c 11,则不会始终生成移动构造函数.有关更多信息,请参见第12.8.20节.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读