[bind10-dev] usage of "virtual" declarations in derived classes

Shane Kerr shane at isc.org
Wed Jul 21 09:52:02 UTC 2010


Jinmei, 

On Wed, 2010-07-21 at 01:34 -0700, JINMEI Tatuya / 神明達哉 wrote:
> Note that we do not *have to* add virtual if we want to allow further
> inheritance and let the grandchild class override its func():
> 
> class MoreDerived : public Derived {
> public:
>     void func();  // this will work equally with or without virtual in "Derived".
> };

In my mind this is, well, C++ being broken. :)

It's not *badly* broken, but it is non-explicit behavior, in that you
have to know the definition of a method in every superclass before you
can know whether it is virtual or not for you.

I tend to think we should always put "virtual" in a method definition if
it is defined as virtual in the parent class, simply to document the
method behavior. Since it *is* virtual, whether we declare it or not,
but it is non-obvious unless you look at the entire hierarchy. :(

--
Shane




More information about the bind10-dev mailing list