Consider the following code
class X{
public:
virtual void foo(X x){ }
virtual void foo(int index){ }
};
class Y : public X{
public:
void foo(int index){ }
};
int main(){
Y y;
y.foo(X()); //Error, see below
}
Class X has overloaded the virtual foo method. One version takes an X and the other one takes an int. Now class Y inherits from X and overrides the method foo(int). The method foo(X) is not to be overridden, it should stay the same.
However, when creating an object of type Y in the main method and calling foo(X), the compiler complains the following:
In function ‘int main()’:
error: no matching function for call to ‘Y::foo(X)’
note: candidate is:
note: virtual void Y::foo(int)
note: no known conversion for argument 1 from ‘X’ to ‘int’
Thus, the only candidate is the overridden foo(int) method. It seems that the other method has simply vanished. If I remove the overriding version, i.e. declare Y as public Y : public X{};, then everything works fine. Why does this happen?
When a derived class defines a member with same name as the one in the base class, the derived class name hides the base class name.
In your case, the function
Y::foohidesX::foo. You need to bring it into the scope ofYas: