|
Boost : |
From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2008-05-03 14:21:43
> On Sat, May 3, 2008 at 8:00 AM, Hartmut Kaiser
> <hartmut.kaiser_at_[hidden]> wrote:
> > What's the problem with making the destructor virtual in the first
> place?
> > Since the class already has other virtual functions this won't
> generate any
> > (significant) additional overhead (the only thing what's added is
> another
> > function pointer to the already existing virtual function table,
> barely
> > something to worry about).
>
> I am not concerned about overhead.
>
> In C++, you use virtual function calls only when your design requires
> polymorphic behavior. My design does not.
Actually, your class _is_ polymorphic, because otherwise you didn't have any
virtual functions in it. You should be aware of the fact that others might
use it as a base class and as soon as it is polymorphic, they might expect
their destructors to be called.
> If GCC issued a warning if you have a non-virtual function in a class
> that has some virtual functions, would you make the non-virtual
> function virtual? (hint: much like the destructor case, using
> non-virtual function in the first place _could_ be a serious bug.)
Your theoretical assumption is completely off topic because neither of those
are special functions, and no sane compiler never ever would complain about
this.
But leaving aside this, yes I would make my base class functions virtual if
somebody had a (even remote) chance of having his code broken because of a
missing virtual keyword.
Regards Hartmut
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk