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