multiple inheritance abiguity

Blake Huff stangmechanic@gmail.com
Thu Jan 19 03:23:00 GMT 2006


Hi all:

The only c++ I've done is followed examples from books, etc, however,  
I modified some code and the following works:

struct C1 {
         void f(double a){
         };
	void f(int a){
         };
};
class M{
         public:
                 C1 gamma;
};
int main(void){
         double c1;
         M m;
         m.gamma.f(c1);
         return 0;
}

This indicates to me that the ambiguity is not in which function to  
call, but rather which struct to call the function on.  The compiler  
keeps track of the expected argument to the function, but not which  
object has which function.. i.e., the code below produces the  
expected errors:

struct C1 {
         void f(double a){
         };
};
struct C2{
         void f(int a){
         };
};

class M{
         public:
                 C1 gamma;
                 C2 beta;
};

int main(void){
         double c1;
         M m;
         m.gamma.f(c1);
         m.beta.f(c1);
         return 0;
}


I hope I've finally given back to the community!

Blake









On Jan 18, 2006, at 8:16 PM, Perry Smith wrote:

> I tried this on the IBM RS/6000 compiler (xlC) and it complains as  
> well.
>
> Good luck
>
> On Jan 18, 2006, at 7:51 PM, Rich Johnson wrote:
>
>> Hi folks--
>>
>> Compiling the following (with no options) produces an ambiguity  
>> error:
>> >>file:  bug.cpp  >>>>>>>>>
>> struct C1 { void f( double ){}; };
>> struct C2 { void f( int ){}; };
>>
>> class M : public C1, public C2 {};
>>
>> int main()
>> {
>>   double c1;
>>   M m;
>>   m.f(c1);
>> }
>> <<<<<<<<<<<<<<<<<
>> The specific error report is:
>> $ g++ bug.cpp -o bug
>> bug.cpp: In function `int main()':
>> bug.cpp:11: error: request for member `f' is ambiguous
>> bug.cpp:2: error: candidates are: void C2::f(int)
>> bug.cpp:1: error:                 void C1::f(double)
>>
>> I've tried both g++(4.0.0 20041026) on Mac OS X 10.4.4, g++(4.0.3  
>> 20051201) on debian(powerpc) unstable. and   g++-3.3.6 (Debian  
>> 1:3.3.6-10).  All three report the same error.
>>
>> Is the code proper C++?  If not, what am I missing?
>> Given that there's there's only one method with a ''void f 
>> (double)" signature where's the source of the ambiguity?
>>
>> Thnx
>> --rich
>>
>>
>

Blake Huff
stangmechanic@gmail.com





More information about the Gcc-help mailing list