Hello,
I'm trying to figure out the proper syntax for addressing a warning I am getting with my project. The specific warning is C4661 and I'll try to explain what is leading to it.
To begin with I have a template class:
1 2 3 4 5
|
template <class T> class EnumMap
{
public:
static char const * m_strings[];
};
| |
I've excluded non-relevant parts. The idea is that you define a variable with your enum templated then somewhere around where your enum is defined, you also implement the map of enum to strings, and there'll be a function that returns the string for a given enum or something to that effect. Assume MYEXPORT is a macro with the appropriate __declspec(dllexport/dllimport) set. For what it's worth, I have no control over this aspect of the design -- it is part of a 3rd party API I am using.
MyClass.h:
1 2 3 4 5 6
|
enum MyEnum { ME_Thing1, ME_Thing2 };
class MYEXPORT MyClass
{
protected:
EnumMap<enum MyEnum> m_myEnumValue;
};
| |
MyClass.cpp:
template <> char const * EnumMap<enum MyEnum>::m_strings[] = { "Thing1", "Thing2", 0 };
The first thing I get with this is a C4251 on the EnumMap itself. This is resolved with:
template class MYEXPORT EnumMap<enum MyEnum>;
in MyClass.h
But then this brings up the C4661 "no suitable definition provided for explicit template instantiation request with [ T=MyEnum ]". I can't for the life of me figure out what to do to address this warning. Any help is appreciated, thanks! :)
I did try moving the code from MyClass.cpp into MyClass.h, but that results in a compile error C2491 "definition of dllimport static data member not allowed" in files which import the exports of my dll.