Topic: Style question about virtual methods


Author: "Cristian Georgescu" <Cristian.Georgescu@worldnet.att.net>
Date: 1997/09/10
Raw View

Re: Style question about virtual methods

Robert C. Martin <rmartin@oma.com> wrote in article
<5v3fnk$7if@netlab.cs.rpi.edu>...
> kjhopps@imation.com wrote:
> >
> > Personally, I prefer the redundant use of "virtual" over leaving it
> > off.  Usually it conveys enough information to make a comment
> > unnecessary.
>
> Me too. In fact, I'd prefer that the language make it an error to
> leave the 'virtual' keyword off.

I fully agree. Maybe the only reason NOT to put a "virtual" in the above
mentioned case is only when you want to say to the user of the class: "Hey,
this is maybe a virual function, by inheritance, but I do not want you to
override it!".

In fact what I would really want would be that in a derived class the non
specification of the keyword "virtual" be equivalent to a "final" like in
Java...

> Actually, I'd prefer that the language default to virtual and force the
> use of a keyword for non-virtual functions.

Maybe this is not the philosophy of C++: class members are "private" by
default, and so is inheritance. Also inheritance is non-virtual by
default...

Besides, different kind of applications make different usage of virtual
functions: in embedded systems virtual functions are some-how used only if
necessary, and therefore they are more rare than in aplication code.

--
Cristian Georgescu
_________________________________________________
    Smith Industries
    Aerospace & Defense Systems
    7-9 Vreeland Road,
    Florham Park, NJ 07932, USA.
_________________________________________________
E-mail: Georgescu_Christian@si.com
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]