首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Boost精神调试枚举类(c++11)编译错误

Boost精神调试枚举类(c++11)编译错误
EN

Stack Overflow用户
提问于 2014-01-17 15:38:55
回答 1查看 537关注 0票数 1

我正在尝试调试一个简单的结构,其中包含一个带有"C:\boost\boost\spirit\home\support\attributes.hpp:1226:的枚举类,但我总是得到编译错误BOOST_SPIRIT_DEBUG_NODE错误:无法将'std::basic_ostream‘lvalue绑定到'std::basic_ostream&&’近'out << val;'“。”

我不知道为什么会出现这样的rvalue错误,我试图为枚举类的operator<<添加手动重载,但这也不起作用。

我正在使用boost 1.55,并试图在Windows8.1 x64上用32位的MinGW编译gcc 4.8。

当我将枚举类更改为默认的c++枚举时,它可以工作,但我希望使用新的枚举类进行正确的命名空间处理。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-17 22:08:38

我不知道为什么会出现这样的rvalue错误,我试图为枚举类的operator<<添加手动重载,但这也不起作用。

我认为这是必需的代码,因为这样做是有效的:

  1. 首先,使用经典的枚举住在Coliru #定义BOOST_SPIRIT_DEBUG #include #include命名空间qi =boost: data_t :qi;struct data_t{ std::string标签;枚举选择{左、右、上、下}选择;data_t(std::string label="default",choice=left):label(std::move(label)),choice=left {} friend std::ostream& operator<<(std::ostream& os,& v) { switch(v) { case (V){ case左:返回os <<“左侧”;大小写右:返回os <<“右”;大小写:返回os << "up";向下:返回os << "down";默认情况:返回os << "?";} friend std::ostream& operator<<(std::ostream& os,data_t const& v) {返回os <<“{标签:”<< v.label <<;选择:“<< v.choice <<”};模板 struct解析器: qi::grammar {解析器():parser::base_type(开始){使用命名空间qi;choice_.add (“左”,data_t::left) (“右”,data_t::right) (“向上”,“data_t::up”)(“下降”,data_t::down);} qi::symbols choice_;qi::rule start;};bool doParse(const std::string& input) { typedef std::string::const_iterator It;auto f(begin(input)),l(end(input));parser p;data_t data;尝试{ bool ok = qi::phrase_parse(f,l,p,qi::space,data);if (ok) { std::cout << "parse \n“;std:cout << " data:”<< data << "\n";} else::cerr <<“解析失败:‘<< std::<< (f,l) <<”’\n;if (f= l) std::cerr <<“拖尾未解析:‘<< std::string(f,l)<<’\n”;返回ok;} catch(const qi::expectation_failure& e) { std::string frag(e.first,e.last);:cerr << e.what() <<“‘<< frag << "'\n";}返回false;} int main() { bool ok = doParse("label1 up");返回ok 0: 255;}
  2. 使用枚举类住在Coliru的第二个 #定义BOOST_SPIRIT_DEBUG #include #include命名空间qi =boost: data_t :qi;struct data_t{ std::string标签;枚举类选择{左、右、上、下}选择;data_t(std::string label="default",choice=Choice::left):label(std::move(标签)),choice=Choice::left {} friend std::ostream& operator<<(std::ostream& os,switch& v) { switch(v) { case选择:左:返回os <<“左”;案例选择::向上:返回os << "up";大小写选择:向下:返回os << "down";默认情况:返回os << "?";}朋友std::ostream& operator<<(std::ostream& os,data_t const& v) {返回os << {标签:“<< v.label <<”;选择:“<< v.choice <<”};}模板 struct解析器: qi::grammar {解析器():parser::base_type(开始){使用命名空间qi;choice_.add (“左”,data_t::Choice::left) (“右”,data_t::Choice::right) (“向上”,“data_t::Choice::up”)(“下降”,data_t::Choice::down),启动%= as_string[ lexeme+graph ] >> lexeme choice_;BOOST_SPIRIT_DEBUG_NODE(开始);}私有: qi::symbols choice_;qi::rule start;};bool doParse(const std::string& input) { typedef std::string::const_iterator It;auto f(begin(input)),l(end(input));parser p;data_t data;尝试{ bool ok = qi::phrase_parse(f,l,p,qi::space,data);if (ok) { std::cout << "parse \n“;std:cout << " data:”<< data << "\n";} else::cerr <<“解析失败:‘<< std::<< (f,l) <<”’\n;if (f= l) std::cerr <<“拖尾未解析:‘<< std::string(f,l)<<’\n”;返回ok;} catch(const qi::expectation_failure& e) { std::string frag(e.first,e.last);:cerr << e.what() <<“‘<< frag << "'\n";}返回false;} int main() { bool ok = doParse("label1 up");返回ok 0: 255;}

我猜您忘了将序列化添加到枚举结构中。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21189844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档