Why is the following code not compiling and how would it be possible to use the function from the base class?
template<typename K> struct Base
{
K foo() { return (K)0; }
};
template<typename K> struct Extension
: public Base<K>
{
K foo(int a) { return (K)a; }
};
int main()
{
Extension<float> e;
e.foo();
return 0;
}
Edit: Ok, I thought that this is only happening with template classes … What is the idea behind the design decision to hide the base class version by its overloaded version from the child class? I mean, declaring both functions in the same class works just fine.
Extension::foois hidingBase::foo. You can use a using delaration to bring it back:Item #33 (“Avoid hiding inherited names”) in Scott Meyers’s “Effective C++” is about this issue.