Timo answer allows you to specialize the class as a whole, which means that the compiler will not automatically copy member functions from the base type to the specialized type.
If you want to specialize a particular method in a class without re-creating everything else, this is a little more complicated. You can do this by passing a template with a zero-size template as an argument, for example:
template<typename T> struct TypeHolder { }; template<typename T> class TemplateBase { public: void methodInterface() { methodImplementation(TypeHolder<T>); } void anotherMethod() {
The compiler embeds the corresponding methodImplementation in the methodInterface , and also removes the structure with a zero size, so it will be exactly the same as if you did specialization only for the member function.
source share