multiple inheritance abiguity

Rich Johnson
Thu Jan 19 14:43:00 GMT 2006

On Jan 19, 2006, at 4:46 AM, Dima Sorkin wrote:

> On 18 Jan 2006 21:22:11 -0600, Gabriel Dos Reis  wrote:
>> The program is indeed in error. There are two kinds of ambiguity:
>>  (1) name lookup ambiguity
>>  (2) call ambiguity.
>> Since overload resolution takes place only after name lookup, you
>> can't expect overload resolution to pick C1::f, when you're  
>> already in
>> trouble with (1).
> I can add that you can read further about it in
> B. Stroustrup "The C++ Programming Language".
> Exactly this case is explained there.

Thanks folks.    I'll look again--specifically for "name ambiguity"  
this time.  (I have the 3rd edition)

I think that what you're telling me is that the name resolution  
algorithm uses _only_ the method's name (not its signature) to first  
select a namespace, and that since an "f(...)" exists in both "M::C1"  
and "M::C2", the compiler is unable to select between them.    
Furthermore this is the algorithm as defined by the language.

What strikes me as odd is that both resolutions phases appear to rely  
on only partial information.  Name resolution doesn't appear to  
consider signatures and overload resolution doesn't appear to  
consider fully qualified names.

I would've expected one of two other algorithms:
1)  Name lookup produces, not a namespace, but a fully qualified  
name.  IOW, given "M" and "f(...)" the name lookup reports two  
candidates, "M::C1::f(....)" and "M::C2::f(...)". Then overload  
ambiguity selects between the two--which are "f(C1*, int)" and "f 
(C2*, double)" when we consider the hidden first arg.  Since M is a  
C2 we'd settle on M::C2::f(double).
2)  Alternately, if the name lookup is to report a namespace,  I'd  
expect it  to be driven by the method's signature.  IOW given "M" and  
"f(double)" the name lookup reports a single candidate, "M::C2".   
Considering the hidden first arg,  the signature "f(M*, double)"  
should match C2's "f(C2*, double)" since M is a C2.


More information about the Gcc-help mailing list