c++ - 具有默认参数的复制构造函数

标签 c++ copy-constructor optional-parameters

据我所知,复制构造函数的格式必须是 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 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 [ Example: X::X(const X&) and X::X(X&,int=1) are copy constructors.

关于c++ - 具有默认参数的复制构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2787569/

相关文章:

c++ - 如何通过编译错误找到 C++ 复制构造函数的使用位置?

c++ - 是否可以定义稍后可以评估的 bool 表达式?

C++ STL 字符串复制构造函数——总是深拷贝?

c++ - 返回无法按值复制的对象

java - 有没有办法让 NULL 值作为 MySql 中的可选条件?

c# - xUnit 测试引擎的 InlineDataAttribute + 可选方法参数

c++ - 函数参数的默认值

c++ - 在字符串末尾添加 double (C++)

c++ - 显性用户定义的强制转换运算符

c++ - 在 C++ 中的数组前添加 '++' 会发生什么?