The template definition allows you to create a function:
void Bar::foo<Impl>(Impl& t)
which is better than the ones you defined that accept the Interface& parameter.
You should make the superclass function more appropriate, perhaps like this:
class Bar { struct fallback { fallback(int) {} }; template<typename T> void foo(T& t, fallback) { std::cout << "generic\n"; } void foo(Interface& t, int) { std::cout << "overload\n"; } public: template<typename T> void foo(T& t) { foo(t, 0); } };
It doesn't seem to actually work, see http://ideone.com/IpBAv
So, you will need a type test inside the general version, looking for subclasses of Interface .
source share