13.4. A Copy-Control Example
Although copy control is most often needed for classes that allocate resources, resource management is not the only reason why a class might need to define these members. Some classes have bookkeeping or other actions that the copy-control members must perform.
As an example of a class that needs copy control in order to do some bookkeeping, we’ll sketch out two classes that might be used in a mail-handling application. These classes, Message
and Folder
, represent, respectively, email (or other kinds of) messages, and directories in which a message might appear. Each Message
can appear in multiple Folder
s. However, there will be only one copy of the contents of any given Message
. That way, if the contents of a
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.