pure virtual functions and name injection

Pierre Chatelier pierre.chatelier@club-internet.fr
Tue Mar 7 13:24:00 GMT 2006

>>  The two functions have different prototypes, I thought that the  
>> compiler was able to differentiate them.
>> Different prototypes, but the same name. The name is what is  
>> causing the error, not the rest of the signature.
> Ok, i guess this is because of the same name, but why is it ok with  
> the C++ standard?
> operator++(int) and operator++() do have the same name, but they  
> are considered as different by a c++ compiler...
Yes, but here it is a problem of visibility, not of resolving.

I think that the point is here :
>> It's a safety feature

> so when calling a::foo() the compiler should redirect the call to  
> the implementation d::foo(), no?
No, when you use the :: operator on a super-class, you explicitely  
ask not to use the "dynamic binding". Otherwise, it would be  
impossible to call the code of super-class
Take that simple example :

struct A
   virtual int f(void) {return 1;}

struct B : public A
   virtual int f(void) {return A::f();} //fortunately, it does not  
call B::f(), or it would be indefinitely recursive

Pierre Chatelier

More information about the Gcc-help mailing list