Rya*_*yan 3 c++ gcc templates partial-specialization visual-c++
有人可以告诉我如何使下面的伪代码与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) {}
};
Run Code Online (Sandbox Code Playgroud)
编码该构造的正确方法是:
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) {}
Run Code Online (Sandbox Code Playgroud)
注意,模板成员函数将被声明里面的类声明,但专业化必须定义之外呢,在命名空间层次.
归档时间: |
|
查看次数: |
6347 次 |
最近记录: |