I am confused by this:
I do not want to use catch-all:
template class Test<int, double>
because the overload get (const int &) will not be defined for all possible explicit instantiations and, therefore, the compiler will adapt to types that do not support it.
Explanation of one specialization does not affect the semantics of other specializations.
The overload get(const int&) is just a member function and it will be created for explicit and implicit specializations, like any other.
Explicit copying can slow down the compiler. It processes each instance no more than once. Unused parts of an implicit instance can be ignored, but by explicitly creating the instance, you force it to handle all of this. In any case, it is not that one instance probably took a measurable amount of time.
To execute errors in the code:
template <class T, class S > // arguments unused class Test { public: template< typename T1 > void* get( const T1& ); void* get(const int& );
Update:
The error occurs due to the absence of a template that does not take precedence over a member template.
Unfortunately, you cannot explicitly specify the template member member of the template. The workaround in this question is to partially specialize, but this will not work because you have a function template.
Workaround No. 2 - SFINAE.
#include <boost/enable_if.hpp> #include <boost/type_traits.hpp> template< typename T1 > boost::disable_if< boost::is_same<T1,int>, void* >::type get( const T1& ); // "turn off" declaration if in conflict void* get(const int& ); // unambiguous overload of the above
If you canβt use Boost,
template< class T > struct disable_if_int { typedef void *type; }; template<> struct disable_if_int<int> {};
...
template< typename T1 > disable_if_int< T1 >::type get( const T1& ); void* get(const int& );