13.1.1. The Copy Constructor
A constructor is the copy constructor if its first parameter is a reference to the class type and any additional parameters have default values:
class Foo {public: Foo(); // default constructor Foo(const Foo&); // copy constructor // ...};
For reasons we’ll explain shortly, the first parameter must be a reference type. That parameter is almost always a reference to const
, although we can define the copy constructor to take a reference to nonconst
. The copy constructor is used implicitly in several circumstances. Hence, the copy constructor usually should not be explicit
(§ 7.5.4, p. 296).
The Synthesized ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.