5.8. Initialization, Destruction, and Copy

Now that num_sequence declares actual data members, we must provide for their initialization. We could leave it to each derived class to initialize these data members, but that’s potentially error-prone. A better design is to provide a base class constructor to handle the initialization of all base class members.

Recall that num_sequence is an abstract base class. We cannot define an independent object of its class; rather, the num_sequence serves as a subobject of each derived class object. For this reason, we declare the base class constructor to be a protected rather than public member.

The initialization of a derived class object consists of the invocation of the base class constructor followed ...

Get Essential C++ 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.