prestokeys
prestokeys

Reputation: 4839

Template specialization within template specialized class

The following compiles in Visual Studio 2015

template <int> struct Test;

template <> struct Test<0> {
    template <int> static void foo();
    template <> static void foo<0>() {}
    template <> static void foo<1>() {}
};

But GCC 5.2 complains error: template-id 'foo<0>' in declaration of primary template template <> static void foo<0>() {}

How to fix the code so that it compiles in both compilers?

Upvotes: 1

Views: 70

Answers (2)

Rumburak
Rumburak

Reputation: 3581

This should work in g++ and MSVC alike:

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>();
}

Upvotes: 1

Wang Weiyi
Wang Weiyi

Reputation: 86

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>() {}

Try this

Upvotes: 3

Related Questions