返回信息流在Dev C++ 下,根据网上文章, 测试带参数的拷贝构造函数,
http://blog.csdn.net/ugg/archive/2006/05/24/753581.aspx
----“拷贝构造函数的第一个参数必须为type X&,或者Type const X&,要么不存在其他参数,如果存在其他参数,其他参数必须有默认值”
,结果发现编译时带默认值的拷贝构造函数会报错!
class MyBase
{public:
MyBase(){}
MyBase(MyBase& other,int a=1);
MyBase(const MyBase& other,int a=1, int b); //1 这里我发现声明是否是带默认值的不影响编译
}
MyBase::MyBase( MyBase& other,int a=1) //2 这个带默认值就报错?
{cout<<"Copy Constructor 2 "<<endl;}
MyBase::MyBase(const MyBase& other,int a, int b=2)
//3 但实现时很奇怪,这个第二拷贝构造函数的参数b带默认值却没有问题??
{cout<<"Copy Constructor 3 "<<endl;
};
error
1 default argument given for parameter 2 of `MyBase::MyBase(const MyBase&, int, int)'
2 after previous specification in `MyBase::MyBase(const MyBase&, int, int)'
请教各位大牛们解释下~
1 按c++标准到底是怎么要求的? 到底带参数的拷贝构造函数需不需默认值?
2 为什么声明部分有误默认值,不影响编译?
3 同样情况下,为什么第二个参数带了默认值却编译通过了? 我实在很费解...
这是一条镜像帖。来源:北邮人论坛 / cpp / #39592同步于 2010/5/25
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
关于带参数的拷贝构造函数
vinci
2010/5/25镜像同步2 回复
订阅后,新回复会通过你的通知中心匿名送达。