2016-02-17 4 views
1

следующие компилируется в 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>() {} 
}; 

Но GCC 5.2 жалуется на ошибку: шаблонный идентификатор «Foo < 0>» в объявлении первичного шаблона шаблона <> статической силы Foo < 0>() {}

Как исправить код, чтобы он компилировался в обоих компиляторах?

ответ

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

Попробуйте

1

Это должно работать в г ++ и 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>(); 
} 

 Смежные вопросы

  • Нет связанных вопросов^_^