相关疑难解决方法(0)

用于模板类中模板函数显式特化的C++语法?

我的代码适用于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)

c++ gcc templates

43
推荐指数
2
解决办法
2万
查看次数

标签 统计

c++ ×1

gcc ×1

templates ×1