gpt4 book ai didi

c++ - 一个简单的 boost.spirit 示例中的 error_invalid_expression 编译错误

转载 作者:行者123 更新时间:2023-11-30 04:07:10 25 4
gpt4 key购买 nike

我正尝试在 Visual Studio 2013 上开始使用 boost.spirit,但遇到了 error_invalid_expression 编译错误。这是代码:

#include <iostream>
#include <string>
#include <boost/spirit/home/qi.hpp>

void main()
{
using namespace boost::spirit::qi;

std::string in("123 234");
std::cout << parse(in.begin(), in.end(), int_) << '\n'; // works fine
std::cout << parse(in.begin(), in.end(), int_ << ' ' << int_) << '\n'; // error here
}

这是模板 barf:

C:\boost\boost/spirit/home/qi/detail/parse.hpp(32): error C2338: error_invalid_expression
C:\boost\boost/spirit/home/qi/parse.hpp(36) : see reference to class template instantiation 'boost::spirit::qi::detail::parse_impl<Expr,void>' being compiled
with
[
Expr=boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::int_> &,boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<const char &>,0>>,2> &,const boost::spirit::terminal<boost::spirit::tag::int_> &>,2>
]
C:\boost\boost/spirit/home/qi/parse.hpp(47) : see reference to function template instantiation 'bool boost::spirit::qi::parse<std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,boost::proto::exprns_::expr<Tag,Args,2>>(Iterator &,Iterator,const Expr &)' being compiled
with
[
Tag=boost::proto::tagns_::tag::shift_left
, Args=boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::int_> &,boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<const char &>,0>>,2> &,const boost::spirit::terminal<boost::spirit::tag::int_> &>
, Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>
, Expr=boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::int_> &,boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<const char &>,0>>,2> &,const boost::spirit::terminal<boost::spirit::tag::int_> &>,2>
]
Spirit.cpp(12) : see reference to function template instantiation 'bool boost::spirit::qi::parse<std::_String_iterator<std::_String_val<std::_Simple_types<char>>>,boost::proto::exprns_::expr<Tag,Args,2>>(const Iterator &,Iterator,const Expr &)' being compiled
with
[
Tag=boost::proto::tagns_::tag::shift_left
, Args=boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::int_> &,boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<const char &>,0>>,2> &,const boost::spirit::terminal<boost::spirit::tag::int_> &>
, Iterator=std::_String_iterator<std::_String_val<std::_Simple_types<char>>>
, Expr=boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::int_> &,boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<const char &>,0>>,2> &,const boost::spirit::terminal<boost::spirit::tag::int_> &>,2>
]
C:\boost\boost/spirit/home/qi/parse.hpp(36): error C2039: 'call' : is not a member of 'boost::spirit::qi::detail::parse_impl<Expr,void>'
with
[
Expr=boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,boost::proto::argsns_::list2<const boost::proto::exprns_::expr<boost::proto::tagns_::tag::shift_left,boost::proto::argsns_::list2<const boost::spirit::terminal<boost::spirit::tag::int_> &,boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,boost::proto::argsns_::term<const char &>,0>>,2> &,const boost::spirit::terminal<boost::spirit::tag::int_> &>,2>
]
C:\boost\boost/spirit/home/qi/parse.hpp(36): error C3861: 'call': identifier not found

我尝试添加上面几行中建议的各种包含文件,但没有帮助。知道这段代码有什么问题吗?

最佳答案

我在复制示例时使用了错误的移位运算符:<<而不是 >> .应该是:

std::cout << parse(in.begin(), in.end(), int_ >> ' ' >> int_) << '\n';

模板错误消息像往常一样有用:-(

关于c++ - 一个简单的 boost.spirit 示例中的 error_invalid_expression 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22587934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com