Case 1: Derived Class Doesn’t Use new
Suppose you begin with the following base class that uses dynamic memory allocation:
// Base Class Using DMAclass baseDMA{private: char * label; int rating;public: baseDMA(const char * l = "null", int r = 0); baseDMA(const baseDMA & rs); virtual ~baseDMA(); baseDMA & operator=(const baseDMA & rs);...};
The declaration contains the special methods that are required when constructors use new
: a destructor, a copy constructor, and an overloaded assignment operator.
Now suppose you derive a lackDMA
class from baseDMA
and that lackDMA
does not use new
or have other unusual design features that require special treatment:
// derived class without DMAclass lacksDMA :public baseDMA{private: char ...
Get C++ Primer Plus 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.