Understanding the canonical class form
For many classes in C++, it is reasonable to follow a pattern for class specification to ensure that a new class contains a full set of desired components. The canonical class form is a robust specification of a class that enables class instances to provide uniform behavior (analogous to standard data types) in areas such as initialization, assignment, argument passing, and usage in return values from functions. The canonical class form will apply to most classes that are intended for either instantiation or that will serve as public base classes for new derived classes. Classes that are intended to serve as private or protected base classes (even if they may be instantiated themselves) may not follow all parts of this idiom.
A class following orthodox canonical form will include the following:
- A default constructor (or an
=default
prototype to explicitly allow this interface) - A copy constructor
- An overloaded assignment operator...