且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

模板“复制构造函数”不会阻止编译器生成的move构造函数

更新时间:2022-05-11 21:42:08

答案很简单-没有( !)模板副本构造函数。即使模板参数与复制构造函数的参数匹配,也不是复制构造函数。

The answer is simple - There is no (!) template copy constructor. Even if the template parameter matches the parameter of a copy constructor it is no copy constructor.

请参见12.8复制和移动类对象

See 12.8 Copying and moving class objects


如果类X的
第一个参数的类型为X&amp ;、 const X&amp ;、 volatile X&或const volatile
X&amp ;,或者没有其他参数,或者所有其他
参数都具有默认参数(8.3.6)。 [示例:X :: X(const X&)
和X :: X(X& int = 1)是副本构造函数。

A non-template constructor for class X is a copy constructor if its first parameter is of type X&, const X&, volatile X& or const volatile X&, and either there are no other parameters or else all other parameters have default arguments (8.3.6). [ Example: X::X(const X&) and X::X(X&,int=1) are copy constructors.

类似地适用于move构造函数

Similar applies to the move constructor