0

我对Spirit很陌生。我正在尝试使用 Qi 在我的嵌入式 Tcl 解释器中解析 CMD 命令的参数。由于某些参数可能会多次使用,因此我需要一个向量来存储相同类型的所有参数。

这是我的问题的一个简化示例,我尝试将整数存储到向量中。

#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/spirit/include/support.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/variant/recursive_variant.hpp>

using std::string;
using std::vector;

namespace {
  namespace qi = boost::spirit::qi;
  namespace phoenix = boost::phoenix;
  namespace ascii = boost::spirit::ascii;

  struct Argument {
    vector<int> svDefine;    // macro definitions
  };
}

BOOST_FUSION_ADAPT_STRUCT
(
 Argument,
 (vector<int>, svDefine)
 )

namespace {
  typedef string::const_iterator SIter;

  struct ArgParser : qi::grammar<SIter, Argument(), ascii::space_type> {
    qi::rule<SIter, Argument(), ascii::space_type> start;

    ArgParser() : ArgParser::base_type(start) {
      using phoenix::at_c;
      using qi::int_;
      using phoenix::push_back;
      using namespace qi::labels;


      start = +("define" >> int_     [push_back(at_c<0>(_val), _1)]);

    }
  };
}

用 g++ 4.5.1 boost 1.51 编译它会产生丢失的错误

In file included from /usr/include/boost/spirit/home/phoenix/container.hpp:10:0,
                 from /usr/include/boost/spirit/home/phoenix.hpp:12,
                 from /usr/include/boost/spirit/include/phoenix.hpp:13,
                 from qi_test.cpp:2:
.....
qi_test.cpp:43:64:   instantiated from here
/usr/include/boost/spirit/home/phoenix/stl/container/container.hpp:492:40: error: ‘struct boost::fusion::vector<int>’ has no member named ‘push_back’
/usr/include/boost/spirit/home/phoenix/stl/container/container.hpp:492:40: error: return-statement with a value, in function returning 'void'
qi_test.cpp: In static member function ‘static 
.....
qi_test.cpp:43:64:   instantiated from here
qi_test.cpp:28:509: error: invalid initialization of reference of type boost::fusion::vector<int>&’ from expression of type ‘std::vector<int>’

基本上我很困惑。不知道出了什么问题。

4

1 回答 1

2

您在这里混合了两种类型的矢量模板类:

std::vector

boost::fusion::vector

如果你只是省略(注释掉)

using std::vector;

事情可能会变得很清楚

于 2012-09-05T15:37:45.167 回答