Specializing inner template based on static const member of outer template parameter
Take for instance the following program:
Code:
#include <iostream>
class A
{
public:
static const int N = 6;
};
template <typename AParam>
class B
{
public:
template <int X>
static void foo()
{
std::cout << "I'm X" << std::endl;
}
template <>
static void foo<AParam::N>()
{
std::cout << "I'm the magic value" << std::endl;
}
};
int main()
{
B<A>::foo<1>();
B<A>::foo<6>();
}
With Visual C++ 2010, this compiles and outputs the following, which is what I would like:
Code:
I'm X
I'm the magic value
gcc however will not compile the code:
Code:
test.cpp:20:15: error: explicit specialization in non-namespace scope 'class B<AParam>'
test.cpp:21:32: error: template-id 'foo<AParam:: N>' in declaration of primary template
Why not? Which compiler is wrong?