Boost logo

Boost :

From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2007-05-06 23:59:26

On 5/6/07, Vladimir Prus <ghost_at_[hidden]> wrote:
> And gcc warns. Desprite warning being overly wordly, it basically
> warns that C2 has virtual function but lacks virtual destructor.
> Adding virtual destructor to C2 makes the example compile without
> warning.
> - Volodya

The gcc warning bothers me at times. Particularly in cases like this:

   struct Callback
        virtual int someCall(Foo foo) = 0;

   void someFunc(Callback * callback);

As shown, the code above is pretty obvious (I hope) - implement a
'Callback' and someFunc will call it with a Foo (for whatever reason).
If I now add a virtual destructor to Callback, am I implying that
someFunc will also delete the callback?!
ie adding the virtual destructor says 'you can delete this from the
base' but I don't always want to say that.
(And yes, in this case I could use a boost::function, or a Callback &
instead of a pointer, etc, but it is just meant to be a simple example
of similar cases that I've seen in actual code.)

The solution we came up with is to include the virtual destructor, but
make it private. And add a comment that the destructor is there to
quiet gcc, but it is private to imply that no one is going to delete
via the base.


Boost list run by bdawes at, gregod at, cpdaniel at, john at