O'Reilly logo

Inside the C++ Object Model by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Semantics of Construction, Destruction, and Copy

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required