gpt4 book ai didi

c++ - 字符串到枚举模板错误

转载 作者:行者123 更新时间:2023-11-30 04:26:47 25 4
gpt4 key购买 nike

我需要将字符串转换为枚举。

我遵循了 String to enum in C++ 中的想法

这是我的代码:

#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

尝试编译时出现以下错误: enter image description here

我正在开发 QT 4.8。

我的错误是什么?

最佳答案

map<string, T>::const_iterator是从属名称,您需要:

 typename map<string, T>::const_iterator iValue= enumMap.find(value);

您可以阅读有关该主题的更多信息 here .

关于c++ - 字符串到枚举模板错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11331187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com