1

给定一个凤凰代码 [a(),b()],我认为正确的行为分别称为 a() 然后 b(),但显然在 boost 1.47 中只调用了第二个函数,这应该是什么?看下面的代码:

struct employee_parser : qi::grammar<Iterator, employee(), ascii::space_type>
{
    employee_parser() : employee_parser::base_type(start)
    {
        using qi::int_;
        using qi::lit;
        using qi::double_;
        using qi::lexeme;
        using ascii::char_;

        using ascii::string;
        using namespace qi::labels;            
        using boost::phoenix::ref;
        using boost::phoenix::val;

        quoted_string %= (lexeme['"' >> +(char_ - '"') >> '"' ]) ;

        start %= (
            lit("employee")
            >> '{'
            >>  int_ >> ','
            >>  quoted_string [std::cout<<ref(text1)<<" \n",ref(text1) = _1]  >> ',' 
            >>  quoted_string >> ','
            >>  double_
            >>  '}'  )                
            ;
    }

    qi::rule<Iterator, std::string(), ascii::space_type> quoted_string;
    qi::rule<Iterator, employee(), ascii::space_type> start;
    std::string text1;
};

为什么不调用第一部分?它是最新的 boost 库中的错误和修复吗?

std::cout<<ref(text1)<<" \n"
4

1 回答 1

3

您可能需要明确包括

#include <boost/spirit/include/phoenix_operator.hpp>

曾经有一个 boost 版本,其中包括主要的 Phoenix 标头未能引入这个必需的标头。

在较新的版本中,这不再需要。我通常建议在以后的版本中切换到 Phoenix V3:

#define BOOST_SPIRIT_USE_PHOENIX_V3

Phoenix V3 具有更多功能、更好的 (c++11) 互操作性,并且通常比 Phoenix V2 更进化

于 2013-10-22T20:46:51.843 回答