An explicit instantiation of a static template member function keeps failing to compile with the message error C2785: 'at_Intermediate CUtil::convert_variant(const VARIANT &)' and '<Unknown>' have different return types
When I make a corresponding class with non-static member functions, the compiler likes me.
// utility class - static methods struct CUtil { template< typename at_Intermediate > static at_Intermediate convert_variant( const VARIANT &v ) ; template<> static VARIANT convert_variant<VARIANT >( const VARIANT &v ) { return v; } // template<> static double convert_variant<double >( const VARIANT &v ) { return v.dblVal; } template<> static long convert_variant<long >( const VARIANT &v ) { return v.lVal ; } template<> static BSTR convert_variant<BSTR >( const VARIANT &v ) { return v.bstrVal; } };
This is a composed question:
-
Why does the compiler complain about a function ‘Unknown’ while it’s clearly known?
-
What triggers this message – it disappears when the function is made global or non-static.
EDIT:
after some useful hints from Josh: is it not allowed to explicitly instantiate template functions within the class declaration?
Apparently you may only use explicit template specialization at namespace scope although I can’t find this in the standard (but GCC says as much). The following works for me (on GCC):
EDIT It is in the standard:
14.7.2.5:
(All emphasis added by me.)