[Exceptional C++ Style] Item 19 - Enforcing Rules for Derived Classes.

Terje Slettebø tslettebo at broadpark.no
Fri Jan 7 05:42:42 EST 2005


> Posted on behalf of David Sullivan:

This one puzzles me a little:

> class Base {
> public:
>   virtual ~Base();
> private:
>   Base(const Base&);
>   Base& operator=(const Base&);
> };
> 
> Using the above recommended technique shown in the Base class above at least
> ensures that three of the four principle class operations produce
> compile time errors if they are not defined in the derived class.

Using the above class as a base class will give you a class that can't be copied
or assigned to (like deriving from boost::noncopiable), and neither can it be
destroyed (!) (you get a link error from missing destructor definition) This
last seems to make it rather useless.

Moreover, there's no point in defining copy constructor, copy assignment and
destructor in a derived class, because the lack of definition of these in the
base class means that they can't be used. So how can the paragraph above hold?
You get errors, anyway (at link time). Am I missing something?

Regards,

Terje



More information about the Effective-cpp mailing list