C ++:默认复制构造函数 [英] C++: Default Copy Constructor

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

问题描述




当你自己没有指定一个

时,会为你创建一个默认的复制构造函数。在这种情况下,默认的复制构造函数将简单地为基元(包括指针)执行按位
按位复制,对于对象类型调用

它们的默认构造函数。


我应该知道的其他任何积分吗?

问候,

A

解决方案




A写道:




默认的复制构造函数是当你自己没有指定一个
时为你创造。在这种情况下,默认的复制构造函数将简单地为基元(包括指针)执行按位复制,对于对象类型调用它们的默认构造函数。




那会很傻。

当然它使用对象类型的复制构造函数。


-

Karl Heinz Buchegger
kb******@gascad.at


>当您没有自己指定一个

时,会为您创建一个默认的复制构造函数。在这种情况下,默认的复制构造函数将简单地为基元(包括指针)执行按位复制,对于对象类型
调用它们的默认构造函数。




为什么这么想?除了它是不正确的,我的意思是。


如果你从一本书得到解释,我建议你在

的未来避免这本书。 />

类的默认复制构造函数复制(非静态)数据

类的成员。复制成员的确切含义取决于成员的类型,就像复制任何对象的含义取决于

对象的类型一样。


Andrew Koenig写道:

当你穿上它时,会为你创建一个默认的复制构造函数自己指定一个
。在这种情况下,默认的复制构造函数将简单地为基元(包括指针)执行按位复制,对于对象类型,调用

它们的默认构造函数。



为什么这么想?除了它是不正确的,我的意思是。

如果你从一本书得到解释,我建议你在



的未来避免这本书。




我很少在糟糕的书中堆积十字军东征。但我会为那本书做一个例外

。有时会出现一个无害的声明,这个声明在一个人的眼中是错误的,但却是无害的;我无法解释为

无害。


Hi,

A default copy constructor is created for you when you don''t specify one
yourself. In such case, the default copy constructor will simply do a
bitwise copy for primitives (including pointers) and for objects types call
their default constructor.

Any others points i should know?
Regards,
A

解决方案



A wrote:


Hi,

A default copy constructor is created for you when you don''t specify one
yourself. In such case, the default copy constructor will simply do a
bitwise copy for primitives (including pointers) and for objects types call
their default constructor.



That would be silly.
Of course it uses the copy constructor for object types.

--
Karl Heinz Buchegger
kb******@gascad.at


> A default copy constructor is created for you when you don''t specify one

yourself. In such case, the default copy constructor will simply do a
bitwise copy for primitives (including pointers) and for objects types call their default constructor.



Why think of it that way? Aside from it being incorrect, I mean.

If you got at explanation from a book, I suggest you avoid that book in the
future.

The default copy constructor for a class copies the (non-static) data
members of the class. Exactly what it means to copy the member depends on
the member''s type, just as the meaning of copying any object depends on the
object''s type.


Andrew Koenig writes:

A default copy constructor is created for you when you don''t specify one
yourself. In such case, the default copy constructor will simply do a
bitwise copy for primitives (including pointers) and for objects types call

their default constructor.



Why think of it that way? Aside from it being incorrect, I mean.

If you got at explanation from a book, I suggest you avoid that book in


the future.



I rarely pile on during "bad book" crusades. But I will make an exception
for that book. Sometimes there is an innocuous statement that is wrong in a
pedant''s eyes but harmless; there is no way I could construe that as
harmless.


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

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