With a template method, that is specialized for a specific class A, is there a way to call the specialized code for the classes deriving from A ?
The minimal example
#include <iostream<
class A
{};
class B : public A
{};
class Templator
{
public :
template <class T>
void dance(T *argument);
};
template <class T>
void Templator::dance(T *argument)
{
std::cout << "General implementation" << std::endl;
}
template<>
void Templator::dance<A> (A* )
{
std::cout << "Specialized implementation" << std::endl;
}
int main()
{
A a;
B b;
Templator tt;
tt.dance(&a);
tt.dance(&b);
return 0;
}
Corresponding output
Specialized implementation
General implementation
In other words, I would like the two outputs to be :
Specialized implementation
Specialized implementation