gpt4 book ai didi

c++ - 不能 phoenix::bind qi::_val with boost 1.53(回归?)

转载 作者:太空狗 更新时间:2023-10-29 21:02:28 24 4
gpt4 key购买 nike

下面的代码,使用 boost::spirit,用于 boost 1.44 和 boost 1.49:

qi::string("a_token")
[
boost::phoenix::bind(&node_t::some_func, *qi::_val, true)
]

我将 boost 更新到 1.53 版,但现在这段代码无法编译。 g++ 提示

error: pointer to member type 'void (node_t::)(bool)' incompatible with object type 'boost::error_cant_deduce_type'

我不知道如何修复它。以下代码编译:

qi::string("a_token")
[
boost::phoenix::bind(&node_t::some_func, (node_t*)0, true)
]

所以我猜问题出在 qi::val_... 是 boost::spirit 的 API 改变了还是我缺少一个包含文件?

我使用的是 g++4.7,--std=c++0x。

这里我尝试了一个小的测试用例来重现这个问题。错误消息不一样(但仍然很大!),但再次引用运算符似乎是问题所在。

#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_bind.hpp>
#include <boost/shared_ptr.hpp>


struct node_t
{
void foo(bool){}
};


int main()
{
namespace qi = boost::spirit::qi;

boost::spirit::qi::rule
<
std::string::const_iterator,
boost::shared_ptr<node_t>(),
boost::spirit::ascii::space_type
> rule;

rule = qi::string("true")
[boost::phoenix::bind(&node_t::foo, *qi::_val, true)];
}

最佳答案

这是根据上面有用的评论做出的回答(感谢 llonesmiz)。

boost::shared_ptr 中所做的更改影响 boost::pheonix 的旧版本尝试在 boost::shared_ptr 上使用解引用运算符 * 时.

在包含 boost::spirit 之前, #define BOOST_SPIRIT_USE_PHOENIX_V3 1可以添加到源中。

此外,还有一些内容,例如 #include <boost/spirit/home/phoenix/ ... >将被删除,因为它会与 spirit v3 冲突.相反,包括 #include <boost/spirit/include/phoenix.hpp> 等文件.

关于c++ - 不能 phoenix::bind qi::_val with boost 1.53(回归?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15233565/

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