0

I have a template class with a static member variable. However, when compiling, I get the following error:

C2371: 'S_TYPES' : redefinition; different basic types

Here's the class in question:

// This all is in Type.h

template<class T>
class Type
{
private:
    static std::map<unsigned int, Type<T>> S_TYPES;
};

template<class T>
std::map<unsigned int, Type<T>> Type<T>::S_TYPES;

How do I fix the error here?

manabreak
  • 5,415
  • 7
  • 39
  • 96

1 Answers1

2

OP edited the question as soon as he saw the error: you were defining a different type from the declared one:

template<class T>
class Type
{
private:
    static std::map<unsigned int, Type<T>> S_TYPES;
};

template<class T>
std::map<unsigned int, Type<T>, TypeInfoComparator> Type<T>::S_TYPES; // different

you should make sure that they do match:

template<class T>
class Type
{
private:
    static std::map<unsigned int, Type<T>> S_TYPES;
};

template<class T>
std::map<unsigned int, Type<T>> Type<T>::S_TYPES;
Marco A.
  • 43,032
  • 26
  • 132
  • 246