Why is the specialization S in A legal and S in B not?
( if B is not commented out ) GCC 4.8.1: error: explicit specialization in non-namespace scope ‘class B’
#include <type_traits>
#include <iostream>
class Y {};
class X {};
struct A {
template<class T, class = void>
class S;
template<class T>
struct S < T, typename std::enable_if< std::is_same< Y, T >::value >::type >
{
int i = 0;
};
template<class T>
struct S < T, typename std::enable_if< std::is_same< X, T >::value >::type >
{
int i = 1;
};
};
/*
class B
{
template<class T>
class S;
template<>
class S < Y > {};
template<>
class S < X > {};
};
*/
int main()
{
A::S< X > asd;
std::cout << asd.i << std::endl;
}