[sldev] Question on Overuse of virtual in C++

Nicholaz Beresford nicholaz at blueflash.cc
Sun Jul 1 13:22:19 PDT 2007



Dirk Moerenhout wrote:
> For starters: I'm no C++ guru so I might be missing something. Feel
> free to enlighten me if so ;-)
> 
> My question is the following:
> Is there a purpose to declare a function virtual if you've no
> intention to overload it? As an example I'd like to take LLTreeNode.

I'd say no.  The only purpose in using virtual is if you
plan to overoad it *and* plan to reference the resulting
objects through a pointer which does not know what the
object is exactly.

On the design side however, unless you are dealing with
extremely performance sensitive code, if in doubt, it's
usually a good idea to make functions virtual and not need
it than the other way round.


> I can imagine it has something to do with the fact that we're using
> template classes but reading what I can find on template classes I
> still don't understand the reasoning.

There's so much leftover stuff (unused members, etc.) in the
viewer that I'd bet that it has no deeper meaning in this case.


Nick


More information about the SLDev mailing list