据我所知,复制构造函数的格式必须是 T(const T&)
或 T(T&)
。如果我想在签名中添加默认参数怎么办?
T(const T&, double f = 1.0);
这是否符合标准?
最佳答案
是的。
§[class.copy]/2:
A non-template constructor for class
X
is a copy constructor if its first parameter is of typeX&
,const X&
,volatile X&
orconst volatile X&
, and either there are no other parameters or else all other parameters have default arguments [ Example:X::X(const X&)
andX::X(X&,int=1)
are copy constructors.
关于c++ - 具有默认参数的复制构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2787569/