Re: multiple inheritance compiler warning

From: John Carson (donaldquixote_at_datafast.net.au)
Date: 03/27/04


Date: Sat, 27 Mar 2004 23:32:08 +1100


"<- Chameleon ->" <cham_gss@hotmail.NOSPAM.com> wrote in message
news:c43ld5$sk4$1@nic.grnet.gr
> warning C4250: 'TTFtoFontGL' : inherits
> 'SaveToFontGL::SaveToFontGL::SaveFont' via dominance
>
> what is this? why via dominance when I have only one "SaveFont"
> implementation?
> My classes:
> -----------------------------------------------
> class FontCreator
> {
> public:
> virtual void SaveFont() = 0;
> ...............................
> };
>
> class FontFromTTF : virtual public FontCreator
> {
> // add extra functionality, but with no implementation of
> "SaveFont()" };
>
> class SaveToFontGL : virtual public FontCreator
> {
> void SaveFont(); // implementation here
> };
>
> class TTFtoFontGL : public FontFromTTF, public SaveToFontGL {};
> -----------------------------------------------
>
> I can work with these warnings but this makes debugging very annoying

(If you looked up the MS explanation for this VC++ warning, it is
unhelpful.)

(The following explanation is taken from Eckel&Allison, Thinking in C++, v2,
pp. 601-3.) The dominance principle is that functions declared in derived
classes dominate functions of the same name declared in their base
classes --- an extension of the basic principle of overriding.

In this case, there are two channels for SaveFont() to get into the
TTFtoFontGL class --- via FontFromTTF and via SaveToFontGL.

Route 1. Via FontFromTTF. The most derived version via this route is the
pure virtual function in FontCreator.

Route 2. Via SaveToFontGL. The most derived version via this route is the
version defined in SaveToFontGL.

Since the most derived version along Route 2 is an override of the most
derived version along Route 1, it wins out via dominance.

Note that the fact that the function in FontCreator is pure virtual is
beside the point. C++ looks for suitable functions in a prescribed order and
it apparently checks for dominance before checking for implementations.

-- 
John Carson
1. To reply to email address, remove donald
2. Don't reply to email address (post here instead)