谁能告诉我如何使以下伪代码与 GCC4 兼容?我想知道它在 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) {}
};
最佳答案
该构造的正确编码方式是:
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) {}
请注意,模板成员函数必须在类声明内部声明,但特化必须在类声明外部定义,在命名空间级别。
关于c++ - 模板参数列表太少问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6029305/