I'm having an issue with declaring and initializing in a small manageable way, the two alternatives which I know do work aren't exactly ideal.
1) Specialized template, providing every single combination of template parameters.
2) Changing a constant variables value.
The sample class layout is like so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
//.h
class Resource
{
typedef typename std::map<std::string, UINT> Label_Map;
typedef Label_Map::iterator Label_Iterator;
template<int ID>
class Label
{
public:
static Resource::Label_Map Labels;
static int MaxValues;
};
};
|
1 2 3 4 5 6 7 8
|
//.cpp
template<int ID> Resource::Data_Map Resource::Label<ID>::Labels; //This works
//Using first method, too bulky
template<> int Resource::Label<Resource::Label_I>::MaxValues = 1;
template<> int Resource::Label<Resource::Property_I>::MaxValues = 1;
template<> int Resource::Label<Resource::Attribute_I>::MaxValues = 1;
template<> int Resource::Label<Resource::Effect_I>::MaxValues = 1;
|
Is there a reason why this works:
template<int ID> Resource::Data_Map Resource::Label<ID>::Labels;
Yet this does not:
template<int ID> int Resource::Label<ID>::MaxValues = 1;
"undefined reference to 'Resource::Label<X>::MaxValues"
If you don't understand quite what I'm asking, please ask, this has been haunting me for quite some time.