Joe Van Dyk wrote:
I'm compiling some code on a IRIX compiler (MIPSpro Compilers: Version
7.4.2m) with all warnings turned on, and I'm getting some of these warnings:
cc-3649 CC: ERROR at end of source
all virtual functions for class "std::__Named_exception" inline: static
virtual table generated
cc-3649 CC: ERROR at end of source
all virtual functions for class "std::logic_error" inline: static virtual
table generated
Anyone have any idea what the heck it means and why it's a problem?
Thanks,
Joe
Many compilers implement virtual functions as follows (note, this is
not required by the standard, but is just a common implementation):
For each class that has virtual functions, create a table (called
vtable or "virtual table") of pointers to all virtual functions. Add
to the class an additional member that is a pointer to this table.
When dispatching a function virtually, follow the pointer to find the
vtable, find the appropriate function pointer in the vtable, call the
function.
Now, this works well in practice, except for the detail that the
compiler must find some place to actually put this table. A common
heuristic is to put it in the compilation unit that contains the
definition of the class's first non-inline virtual function. Obviously
this doesn't work if there are no non-inline virtual functions, as in
your case.
Faced with this situation, some compilers will use other smart tricks,
and others will generate a separate copy of the vtable in every
compilation in which the class is used, which may possibly increase the
runtime size of your program considerably. My guess is that your
compiler chooses this latter route, and is warning you about it.
The obvious solution is to not have any classes in which all virtual
functions are inlined. Such a concept is rarely useful anyway. A call
to a virtual function can only be inlined if the static type is known,
in which case why did you make the function virtual?
--
Alan Johnson