![](/img/trans.png)
[英]Boost Spirit code, compilable with msvc, but compilation erros with gcc
[英]Boost Spirit v2 gcc compilation error which does not show up using msvc
我最近在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;
};
然后將其傳遞給一個短語_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’
我感到沮喪的是,Visual Studio似乎更願意編譯和運行代碼。 我希望明智的互聯網可以向我展示我的錯誤所在。
我認為這里的問題是std::string
的begin()
和end()
,請嘗試以下操作:
std::string::const_iterator begin = txt.begin();
std::string::const_iterator end = txt.end();
然后將其傳遞給:
phrase_parse(begin, end, foobar, space, result)
我相信的問題是,在其他任何地方您都使用const_iterator
類型,但非const字符串上的begin()
, end()
返回一個正常的迭代器。
錯誤的關鍵部分是這個位:
parse(__ gnu_cxx :: __normal_iterator ,std :: allocator>>&,const __gnu_cxx :: __normal_iterator ,std :: allocator>>&
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.