使用默认参数复制构造函数 [英] copy constructor with default arguments

查看:81
本文介绍了使用默认参数复制构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,复制构造函数的格式必须为T(const T&)T(T&).如果我想向签名添加默认参数怎么办?

As far as I know, the copy constructor must be of the form T(const T&) or T(T&). What if I wanted to add default arguments to the signature?

T(const T&, double f = 1.0);

是否符合标准?

推荐答案

是.

§ [class.copy]/2:

§[class.copy]/2:

X的非模板构造函数是 copy 构造函数,如果它的第一个参数的类型为X&const X&volatile X&const volatile X&,并且其中一个没有其他参数或所有其他参数都有默认参数 [示例: 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 [ Example: X::X(const X&) and X::X(X&,int=1) are copy constructors.

这篇关于使用默认参数复制构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆