8.3. Reference Counts

The class design boilerplate from Chapter 7 organizes and centralizes the important dynamic behaviors of objects with copy() and free(). In particular, the boilerplate makes sure that different objects do not use the same resource (free store memory, files, and so forth) and that changes to one object's state do not affect the state of another one. This approach makes class design robust and consistent with objects that you instantiate.

Classes that allocate and deallocate resources in their constructors and destructors are candidates for reference counts that manage a resource. Reference counts improve efficiency with classes that read from resources more often than they write to them. Applications that call copy(), for ...

Get Navigating C++ and Object-Oriented Design 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.