pure virtual functions and name injection

Pierre Chatelier ktd@club-internet.fr
Mon Mar 6 21:28:00 GMT 2006

Thanks for the answer, but everything is not yet absolutely clear to me:

>> Why should I inject the "foo" name from a into b ?
> So that the compiler can find b::foo();
I agree, but what surprised me is that it is necessary. I have a long  
experience with C++, and it is the first time that I do not  
understand why it can't resolve a name. It is a use of "using" that I  
was not aware of.

> Different prototypes, but the same name.  The name is what is  
> causing the error, not the rest of the signature.
But gcc internally use name mangling according to the prototype,  
right ? So that I would have expect a real call to foo() to be  
explicit enough to resolve.

> To avoid this kind of situation, I recommend using a different  
> method name for the method with the different signature.
Agreed, but my problem here is to understand before :-)

>> Then it compiles but there is a *link* error !  Can somebody  
>> explain me what happens ?
> You have not defined the a::foo function anywhere.  So there is a  
> link error.
Certainly, but in this case, I was rather expecting a compile error,  
claiming that the pure virtual method had no body. On the contrary,  
gcc has accepted it, so that I thought that it has found the right foo 
() !


Pierre Chatelier

More information about the Gcc-help mailing list