Boost Spirit v2 gcc编译错误,它不会显示使用msvc

时间:2011-01-31 20:01:29

标签: c++ gcc boost

我最近在windows中编写了一些精神解析代码,我最近试图在ubuntu框上构建并遇到了我正在努力解决的编译错误。

经过一些黑客攻击和削减之后,我设法提出了这个示例代码片段,它表现出相同的行为:

struct FooParser
: spirit::qi::grammar<
    std::string::const_iterator, 
    double(), 
    spirit::qi::ascii::space_type>
{
    FooParser() : FooParser::base_type(a_rule)
    {
        using namespace boost::spirit::qi;
        a_rule = double_;
    }

    spirit::qi::rule<
        string::const_iterator,
        double(),
        spirit::qi::ascii::space_type> a_rule;
};

然后传递给phrase_parse,如:

double result;
std::string txt;
FooParser foobar;
//...
if(phrase_parse(txt.begin(), txt.end(), foobar, space, result))
{
//do something
}

编译时会产生以下错误:

boost/spirit/home/qi/reference.hpp:41: error: no matching function for call to 
‘boost::spirit::qi::rule<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char,
 std::char_traits<char>, std::allocator<char> > >, double(), 
boost::proto::exprns_::expr<boost::proto::tag::terminal, 
boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space, 
boost::spirit::char_encoding::ascii> >, 0l>, boost::fusion::unused_type, 
boost::fusion::unused_type>::parse(__gnu_cxx::__normal_iterator<char*, 
std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, const 
__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, 
std::allocator<char> > >&, const boost::fusion::unused_type&, const 
boost::spirit::qi::char_class<boost::spirit::tag::char_code<boost::spirit::tag::space, 
boost::spirit::char_encoding::ascii> >&, double&) const’

我觉得令人沮丧的是视觉工作室似乎非常乐意编译和运行代码。我希望明智的互联网可以告诉我我的错误。

1 个答案:

答案 0 :(得分:5)

我认为这里的问题是begin()的{​​{1}}和end(),请尝试以下方法:

std::string

然后传递给:

std::string::const_iterator begin = txt.begin();
std::string::const_iterator end = txt.end();

我认为问题在于你使用类型phrase_parse(begin, end, foobar, space, result) 的所有其他地方,但非const字符串上的const_iteratorbegin()会返回正常的迭代器。

错误的关键部分是这一点:

解析(__ gnu_cxx :: __ normal_iterator ,std :: allocator&gt;&gt;&amp;,const __gnu_cxx ::的 __ normal_iterator 下, std :: allocator&gt; &GT;&安培;