模板专业化中的模板专业化 class
Template specialization within template specialized class
以下编译于Visual Studio2015
template <int> struct Test;
template <> struct Test<0> {
template <int> static void foo();
template <> static void foo<0>() {}
template <> static void foo<1>() {}
};
但 GCC 5.2 报错:主模板声明中的模板 ID 'foo<0>'
模板 <> static void foo<0>() {}
如何修复代码以使其在两个编译器中都能编译?
template<int> struct Test;
template<> struct Test<0> {
template<int> static void foo();
};
template<> void Test<0>::foo<0>() {}
template<> void Test<0>::foo<1>() {}
试试这个
这应该在 g++ 和 MSVC 中同样有效:
template <int>
struct Test;
template <>
struct Test<0>
{
template <int>
static void foo();
};
template <>
void Test<0>::foo<1>()
{
}
int main()
{
Test<0>::foo<1>();
}
以下编译于Visual Studio2015
template <int> struct Test;
template <> struct Test<0> {
template <int> static void foo();
template <> static void foo<0>() {}
template <> static void foo<1>() {}
};
但 GCC 5.2 报错:主模板声明中的模板 ID 'foo<0>' 模板 <> static void foo<0>() {}
如何修复代码以使其在两个编译器中都能编译?
template<int> struct Test;
template<> struct Test<0> {
template<int> static void foo();
};
template<> void Test<0>::foo<0>() {}
template<> void Test<0>::foo<1>() {}
试试这个
这应该在 g++ 和 MSVC 中同样有效:
template <int>
struct Test;
template <>
struct Test<0>
{
template <int>
static void foo();
};
template <>
void Test<0>::foo<1>()
{
}
int main()
{
Test<0>::foo<1>();
}