I'm confused by this output. I would expect the more specific
overloaded function to be selected:
#include <iostream>
class Base
{
};
class Derived : public Base
{};
class Foo
{
public:
template<typena me U>
void bar(U* in, int a)
{
std::cout<<"Gen eric Call"<<std::end l;
}
void bar(Base* in, int a)
{
std::cout<<"A more appropriate choice"<<std::e ndl;
}
};
int main()
{
Derived *d = new Derived;
Foo foo;
foo.bar(d,1,1) // calling with derived
}
This prints "Generic Call". Is this correct? Why? I would have
expected the compiler to either pick the more specific overload, or
complain that the call was ambiguous.
What's going on ?
What's the fix ?
Thanks in advance,