13.1.1. The Copy Constructor

Image

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 explicit7.5.4, p. 296).

The Synthesized ...

Get C++ Primer, Fifth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.