【发布时间】:2011-01-07 01:20:44
【问题描述】:
我的代码在 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>'
我了解 GCC 希望我将我的显式专业化移到课堂之外,但我无法弄清楚语法。有什么想法吗?
// the following is not correct syntax, what is?
template< typename T >
template<>
inline void C< T >::f< tag >( T ) {}
【问题讨论】: