我在Fedora 19上的编译器gcc 4.8.1
我的代码是这样的:
#include <iostream>
#include <vector>
#include <string>
#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/adapted.hpp>
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
struct expr {
std::vector<int> prots;
};
BOOST_FUSION_ADAPT_STRUCT(
struct expr,
(std::vector<int>, prots)
)
template <class Iterator>
struct protocol : qi::grammar<Iterator, expr(), ascii::space_type> {
protocol() : protocol::base_type(start) {
using namespace qi;
start %= int_ % ',';
}
qi::rule<Iterator, expr(), ascii::space_type> start;
};
int main(int argc, char* argv[]) {
if (argc < 2)
return -1;
std::string str(argv[1]);
std::string::const_iterator beg = str.begin();
std::string::const_iterator end = str.end();
protocol<std::string::const_iterator> g;
expr e;
bool r = qi::phrase_parse(beg, end, g, ascii::space, e);
if (!r || beg != end) {
std::cout << "parse failed!" << std::endl;
return -1;
} else
std::cout << "parse success!" << std::endl;
return 0;
}
编译失败,有很多编译器消息。
讯息
/usr/local/include/boost/spirit/home/support/container.hpp:116:12: error: no type named 'value_type' in 'struct expr'
/usr/local/include/boost/spirit/home/qi/detail/pass_container.hpp:296:66: error: no type named 'type' in 'struct boost::spirit::traits::container_value<expr, void>'
/usr/local/include/boost/spirit/home/qi/detail/pass_container.hpp:309:15: error: no type named 'type' in 'struct boost::spirit::traits::container_value<expr, void>'
但是当我把它改成下面时,就编译了。
std::vector<int> e;
bool r = qi::phrase_parse(beg, end, (*qi::int_), ascii::space, e);
有人帮忙吗?