Raj*_*war 6 c++ constructor c++03
由于我对这个问题有疑问(对于C++ 03)我在这里发布它.我刚刚读到了转换构造函数,它说明了
"要成为转换构造函数,构造函数必须具有单个参数,并且在没有关键字显式的情况下声明."
现在我的问题是复制构造函数是否可以被称为转换构造函数,只要它没有显式声明?它有资格成为一个吗?我相信它不能被称为转换构造函数,因为它只接受相同的类型参数,导致无转换.例如
foo a;
foo b;
a = 100; //a Conversion constructor would be called (i.e) foo(int a){...}
a = b ; //Since both objects are same type and have been initialized the assignment operator will be called (if there is an overloaded version otherwise the default will be called)
Run Code Online (Sandbox Code Playgroud)
我的理解是否正确?
dyp*_*dyp 10
引用标准:
[class.conv.ctor]/3
非显式复制构造函数(12.8)是转换构造函数.隐式声明的复制构造函数不是显式构造函数; 可以调用它来进行隐式类型转换.
所以,是的,复制者是转换器.
另请注意[conv]/1,它在注释中指定并指出:
注意:标准转换序列可以为空,即它可以不包含任何转换.
和/ 3:
当且仅当声明格式正确时,表达式
e才能隐式转换为类型TT t=e;
因此隐式转换集包含空转换.