I have a bunch of classes that have a static member that is an enum value. And I have a map somewhere else with this enum as key. Now if I use a template parameter in a function to access the map, I get an undefined reference.
To make it clear, here is a simplified non-working example :
template<int T>
struct A
{
static const int Type = T;
}
template<class T>
void fun()
{
cout << map_[T::Type] << endl;
}
map<int, string> map_{{1337, "1337"}};
main :
fun<A<1337>();
gives me (g++ 4.7) :
undefined reference to `(anonymous namespace)::A<1337>::Type'
However this :
template<class T>
void fun()
{
auto key = T::Type;
cout << map_[key] << endl;
}
Compile and prints 1337
Can someone explain me this behavior?