Topic: inlining virtual functions (fwd)


Author: scotty@cinenet.net (J Scott Peter XXXIII i/iii)
Date: 1996/07/15
Raw View
In article <199606291634.SAA15233@dijon.daimi.aau.dk>,
Claus L{gel Rasmussen <shakti@daimi.aau.dk> wrote:
> Alex Martelli wrote:
> >ccwf@thales.klab.caltech.edu (Charles Fu) writes:
>
> >>It might also be interesting to allow each virtual member function to
> >>specify that it can/cannot be overridden in a derived class.  I don't
> >>know of any examples from other languages for such a fine-grained
> >>mechanism and don't know all the repercussions.
>
> With respect to C++ one could say, that it have never been the aim of
> C++ to be a good modelling language and that calls to virtual functions
> are already as efficient as can be. Finally the inheritance argument
> is not relevant in a C++ context.
>
> I therefore fail to see any (substantial) reason to include a "final"
> declaration in C++.
>

As you yourself agreed, calls to virtual functions are *not* as efficient as
they could be in the case of a virtual function having no overriding
versions in derived classes.  In those cases, the compiler can inline the
call, or at least avoid the vtbl lookup.

Here is a very simple explanation for why some sort of "final" capability is
useful in C++: When a member function is declared for the "first" time in a
hierarchy (not overriding a base-class function), it has the option of being
virtual or non-virtual.  That is, it tells the compiler whether it plans to
be dynamically overridden (virtual), or not (final).  *All* member functions
should have this option, including those that override base-class versions.

---
John Scott Peter XXXIII i/iii  // Wrong thinking is punishable.
Software Engineer             // Right thinking will be as quickly rewarded.
Venice, CA                   // You will find it an effective combination.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]