Reputation: 3934
I need to convert a String to enum.
I followed the idea in String to enum in C++
And this is my code:
#ifndef ENUMPARSER_H
#define ENUMPARSER_H
#include <iostream>
#include <map>
#include <string>
enum MYENUM
{
VAL1,
VAL2
};
using namespace std;
template <typename T>
class EnumParser
{
map<string, T> enumMap;
public:
EnumParser();
T ParseEnum(const string &value)
{
map<string, T>::const_iterator iValue= enumMap.find(value);
if(iValue!=enumMap.end())
return iValue->second;
}
};
EnumParser<MYENUM>::EnumParser()
{
enumMap["VAL1"] = VAL1;
enumMap["VAL2"] = VAL2;
}
#endif // ENUMPARSER_H
When tring to compile it I get the following errors:
I'm working on QT 4.8.
What is my mistake?
Upvotes: 1
Views: 531
Reputation: 258618
map<string, T>::const_iterator
is a dependent name, you need:
typename map<string, T>::const_iterator iValue= enumMap.find(value);
You can read more about the subject here.
Upvotes: 2