我正在尝试使用枚举类和 std::string 的 std::map,但我遇到了一些错误。我正在使用带有 -std=c++0x 的 gcc 4.4.7(这是固定的)
在 .h 文件中:
enum class state_t{
unknown,
off,
on,
fault
};
typedef std::map<state_t,std::string> statemap_t;
在 .cpp 文件中:
statemap_t state={
{state_t::unknown,"unknown"}
{state_t::off,"off"}
{state_t::on,"on"}
{state_t::fault,"fault"}
}
允许状态转换的方法如下:
Foo::allowStateChange(const state_t localState, const state_t globalState, const state_t newState){
//Some code to verify if the state transition is allowed.
std::cout << "Device Local State:" << state.find(localState)->second << "Device Global State:" << state.find(globalState)->second << "Device New State:" << state.find(newState)->second << std::endl;
}
编译时,我得到下一个错误:错误:'state_t'和'state_t'类型的无效操作数到二进制'operator<'
如果我将其更改enum class state_t
为enum state_t
它可以工作。有没有办法在地图中找到枚举类?
提前致谢。