我的代码适用于VC9(Microsoft Visual C++ 2008 SP1)但不适用于GCC 4.2(在Mac上):
struct tag {};
template< typename T >
struct C
{
template< typename Tag >
void f( T ); // declaration only
template<>
inline void f< tag >( T ) {} // ERROR: explicit specialization in
}; // non-namespace scope 'structC<T>'
Run Code Online (Sandbox Code Playgroud)
我知道GCC希望我在课外移动我的显式专业,但我无法弄清楚语法.有任何想法吗?
// the following is not correct syntax, what is?
template< typename T >
template<>
inline void C< T >::f< tag >( T ) {}
Run Code Online (Sandbox Code Playgroud)