0

Say that six times fast... Why doesn't this compile in MSVC 2010?

class A {
public:
    void foo(int a, int b) { };
    void foo(int a) { };
};
class B: public A {
public:
    void foo(int a, int b) { }; // <-- comment this out to compile
};

int main(int argc, char* argv[])
{
    B b;
    b.foo(1); // <-- doesn't compile... shouldn't B just inherit this overload?
}
johnnycrash
  • 5,184
  • 5
  • 34
  • 58

1 Answers1

1

When you override, you override the name, not the specific overload. So it hides all overloads from the base class. To address, you can put using A::foo; in your derived class to bring the overloads down into B.

kec
  • 2,099
  • 11
  • 17