开发者

Too few template-parameter-lists problem

Can anybody please tell me how to make the following pseudo-code compatible with GCC4? I wonder how it work开发者_运维问答s under MSVC...

typedef int TypeA;
typedef float TypeB;

class MyClass
{
// No base template function, only partially specialized functions...
    inline TypeA myFunction<TypeA>(int a, int b) {} //error: Too few template-parameter-lists
    template<> inline TypeB myFunction<TypeB>(int a, int b) {}
};


The proper way of coding that construct would be:

typedef int TypeA;
typedef float TypeB;
class MyClass
{
    template <typename T> 
    T myFunction( int a, int b );
};
template <> 
inline TypeA MyClass::myFunction<TypeA>(int a, int b) {}
template <> 
inline TypeB MyClass::myFunction<TypeB>(int a, int b) {}

Note that the template member function has to be declared inside the class declaration, but specializations must be defined outside of it, at namespace level.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜