By simply defining the foo member function in the derived class, you hid all the foo functions in the base class.
You need to clarify the question a bit - are you worried that foo in a derived class is not a proper replacement for foo in a base class? I find it difficult to determine what you are really asking.
Edit: Based on your changes and additional comments, I think you have a misunderstanding of how work in C ++ is hiding. In this case, it does not matter that one function is constant and the other is not - as soon as C ++ finds the function foo in the derived class, it stops looking elsewhere! This is usually a huge trap for people. Consider the following:
class Base { void foo(double d) { cout << d; } }; class Derived : public Base { void foo(int i) { cout << i; } }; Derived obj; obj.foo(123.456);
What do you think, on the way out? This is 123! You probably received a compiler warning saying that a double value would be truncated. Despite the fact that the signature of a function that takes a double is obviously the best match, it was never taken into account - it was hidden.
source share