The following code prints:
generic
overload
But what I wanted is that the overload or the specialization were called in both cases, not the generic one. I'm not trying to mix overloading with template specialization, they're here together because none worked as I expected. Is there any template magic to accomplish this?
#include <iostream>
class Interface {};
class Impl: public Interface {};
class Bar
{
public:
template<typename T> void foo(T& t) {
std::cout << "generic\n";
}
void foo(Interface& t) {
std::cout << "overload\n";
}
};
template<> void Bar::foo<Interface>(Interface& t) {
std::cout << "specialization\n";
}
int main() {
Bar bar;
Impl impl;
Interface& interface = impl;
bar.foo(impl);
bar.foo(interface);
return 0;
}