Jump to content

Talk:Copy constructor (C++)

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gfaraj (talk | contribs) at 04:18, 23 October 2006. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Why do we need to use & in the definition of a copy constructor? --Anonymous


This article has an error regarding the implicit copy constructor. It does not perform a "byte-by-byte" copy of its members, since its members could have user-defined copy constructors as well. The standard specifies:

The implicitly-defined copy constructor for class X performs a memberwise copy of its subobjects. The order of 
copying is the same as the order of initialization of bases and members in a user-defined constructor (see 12.6.2). 
Each subobject is copied in the manner appropriate to its type:

— if the subobject is of class type, the copy constructor for the class is used;
— if the subobject is an array, each element is copied, in the manner appropriate to the element type;
— if the subobject is of scalar type, the built-in assignment operator is used.

Virtual base class subobjects shall be copied only once by the implicitly-defined copy constructor (see
12.6.2).

I will correct this now.

--Gfaraj 04:18, 23 October 2006 (UTC)[reply]