Where to put the vtbl?

This is a "Quality of product" issue I'd like to raise to HP (concerning the ANSI compiler), possibly getting support in the news.

The rule for deciding where to generate the virtual table of a class (in most implementations where there is one), is (mail from HP's Joe Coha): the classic "drop the copy of the virtual table with the 'key' function." The 'key' function is the first non-inline, non-pure virtual member function that the compiler sees. If one is not seen, a static copy of the virtual table must be dropped in every object file generated.

I have presented one point, and made one question.

The point concerns pure virtual destructors: shouldn't destructors be considered a special case? Even when pure, they need to be defined!

The question is actually the heart of the issue I want to raise here: in what is the problem of getting rid of (per file) static "outlined inlines" (such as the virtual table and the destructor here) different from this of getting rid of local template instantiations? Can't the same techniques (which I don't fully understand) apply?

In other terms, can't one do anything better than generating static versions of the virtual tables (and of similar code or data)? In what does this differ from the problem of generating unique global template instantiations?


Motivation

The programming style I favor in C++ is based on mixin inheritance. I tighly separate interface classes (abstract, dataless, but possibly containing code) from implementation ones. The first are "abstract mixins", the other "concrete mixins". My actual instantiable classes (concrete mixins usually are not instantiable, since they only partly define implementations for the complex interfaces) multiply inherit from both kinds. Only, abstract mixin hierarchies are arbitrarily deep, whereas there is only one level of concrete mixin inheritance (i.e. concrete mixins never inherit from anything else but abstract mixins, and instantiable classes are hidden (apart from factories) so that nothing can inherit from them.

Virtual inheritance is used heavily.

This scheme has been advocated in the news e.g. by John Max Skaller, and in the literature by Stroustrup and Koenig.

The bottom line is that I'd like to have lots of small abstract mixins. Ideally, these classes should often be fully inlined (meaning that they should fit entirely within a header file).

I therefore systematically incur a penalty, either the burden of needing to write artifact source files (typically containing only a definition for the destructor), or to get lots of duplicated static vtbls (and outlined inline member functions, such as e.g. destructors).


Table of contents
Marc Girod
Last modified: Sat Feb 28 14:29:42 EET 1998