May 1996
Intermediate to advanced
304 pages
5h 54m
English
Consider the following abstract base class declaration:
class Abstract_base {
public:
virtual ~Abstract_base() = 0;
virtual void interface() const = 0;
virtual const char*
mumble () const { return _mumble; }
protected:
char *_mumble;
}; Do you see any problems? Although the class is designed to serve as an abstract base class (the presence of a pure virtual function disallows independent instances of Abstract_base to be created), the class still requires an explicit constructor in order to initialize its one data member, _mumble. Without that initialization, a local object of a class derived from Abstract_base will have its instance of _mumble uninitialized. For example:
class Concrete_derived ...
Read now
Unlock full access