Item 13. Copy Operations

Copy construction and copy assignment are different operations. Technically, they have nothing to do with each other, but socially they hang out together and must be compatible.

image

Copying is such a pervasive operation that it’s even more important than usual to follow convention. These operations are always declared as a pair, with the signatures above (but see auto_ptr Is Unusual [43, 147] and Preventing Copying [32, 111]). That is, for a class X, the copy constructor should be declared X(const X &), and the copy assignment operator should be declared X &operator =(const X &). It’s common and often a good idea to define ...

Get C++ Common Knowledge: Essential Intermediate Programming 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.