[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

OT: C++ help



Feel free to redirect me to a better place to ask if you know of one.

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.

If a using declaration should be enough to fix this, where should I
place? Or a better fix?

Thanks,
- Jordi G. H.


Reply to: