隐式复制构造函数 [英] Implicit copy constructor
问题描述
n3337的报价12.3.1 / 3
Quote from n3337 12.3.1/3
非显式复制/移动构造函数(12.8) b构造函数。隐式声明的复制/移动构造函数不是一个
显式构造函数;
A non-explicit copy/move constructor (12.8) is a converting constructor. An implicitly-declared copy/move constructor is not an explicit constructor; it may be called for implicit type conversions.
来自ANSI ISO IEC 14882 2003的报价
Quote from ANSI ISO IEC 14882 2003
非显式复制构造函数(12.8)是转换构造函数。
隐式声明的拷贝构造函数不是显式构造函数;
它可能被调用隐式类型转换。
A non-explicit copy-constructor (12.8) is a converting constructor. An implicitly-declared copy constructor is not an explicit constructor; it may be called for implicit type conversions.
我没有想法,构造函数
可用于 implicit
类型转换
。如果是在标准的错误印刷/错误,为什么它不会更正,因为C ++ 03标准?任何链接和示例(如果我们可以使用类型转换
)非常感谢。
I have no ideas, how copy-constructor
can be used for implicit
type conversions
. And if it's misprint/error in standard, why it's not corrected since C++03 standard? Any links and examples (if we can use it for type conversions
) are really appreciated.
推荐答案
复制构造函数可以通过对派生类型的对象进行切片来转换:
A copy constructor can convert from an object of a derived type by slicing it:
struct A {};
struct B : A {};
B b;
A a = b; // uses A::A(A const&) to convert B to A
这篇关于隐式复制构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!