Derived class hiding a name
The following code will not compile:
class foo{};
class A{
public:
void f(int a ){a++;};
private:
virtual void f(foo a) = 0;
};
class B : public A{
private:
virtual void f(foo a){};
};
int main(){
B b;
int a=0;
b.f(a);
}
The problem seems to be that all of my functions being named f are
somehow colliding with each other. It seems to me that the
call b.f(a) is unambiguosly pointing to A::f(int), but gcc disagrees.
I can fix this if I namespace the b.f(a) call, but that's a little
ugly. I can also fix it if I put a forwarding function inside B that
calls the proper function inside A, also a little ugly. I could also
mangle my functions' names, but I really feel that's the compiler's
job, not mine, especially since I think I already provided enough
context with a function signature. Also, I'd like to keep the
functions' names as they are, since they reflect an underlying
mathematical structure that really could use the same names.
If a using declaration should be enough to fix this, where should I
place? Or a better fix?
Thanks,
- Jordi G. H.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]