pure virtual functions and name injection
Jérôme Cornet
jerome@aldorande.net
Tue Mar 7 09:28:00 GMT 2006
Hello,
i saw this message here on the mailing list archive:
http://gcc.gnu.org/ml/gcc-help/2006-03/msg00027.html
and followed the thread with great interest.
John Love-Jensen wrote:
> > 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...
> To avoid this kind of situation, I recommend using a different
> method name
> for the method with the different signature.
>
> >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.
Technically, a::foo() is not "defined" anywhere (i understand what
you mean),
but it does not need to, since it is a pure virtual functions.
But a::foo() is "implemented" in class "d" (return 1), so when
calling a::foo() the
compiler should redirect the call to the implementation d::foo(), no?
jérôme cornet
More information about the Gcc-help
mailing list