c++ - Qi语义 Action 调用错误无匹配函数

标签 c++ boost boost-spirit boost-spirit-qi

我的语法部分如下:

typedef SemanticActions< IterType > SemanticActionsType;

string_ %= lexeme[ +( spirit::qi::alnum | punct )];

component_ = lit( '-' ) >> string_[boost::bind( &SemanticActionsType::new_component_name, &actions_, _1, _2 )] 

以及对应的语义 Action 类:

template< typename IterType >
class SemanticActions
{
public:
    SemanticActions( Design_p d ) : design_( d )
    {
    }

    void print(int const& i) const
    {
        std::cout << i << std::endl;
    }

    void new_component_name ( std::string::iterator const b, std::string::iterator const e) const
    {
        cout << "new component name" << endl;
    }

我可以让“print”函数从 int_ token 调用,但我无法让 new_component_name 从 string_ token 调用。

我收到以下错误:boost/include/boost/bind/bind.hpp:397:9: 没有匹配函数来调用 'const boost::_mfi::cmf2 >, std::__1::__wrap_iter, std::__1::__wrap_iter >'

我已经尝试了迭代器对参数以及“std::string & s const”参数。

最佳答案

您需要使用 phoenix bind(带有 qi 占位符)

namespace phx = boost::phoenix;

component_ = (lit( '-' ) >> string_)
       [phx::bind( &SemanticActionsType::new_component_name, &actions_, qi::_1, qi::_2 )];

请注意 添加的括号 (!),否则 SA 将仅附加到 string_ 规则。

如果你还没有使用它,我可以建议使用推荐的

#define BOOST_SPIRIT_USE_PHOENIX_V3

它解决了 Spirit 语义操作的许多问题(有时甚至需要在最近的编译器上编译示例)。

关于c++ - Qi语义 Action 调用错误无匹配函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20861753/

相关文章:

c++ - 在监 window 口中显示浮点值的 Eclipse

c++ - Visual C++ 优化选项 - 如何改进代码输出?

c++ - 重构决策:消息队列库,同步调用者或卸载在库中创建专用的读/写线程

c++ - 使用来自 Boost.Spirit 的 Lex 和 Qi 在语法规则中使用词法分析器标记属性

c++ - fusion 适应结构中的 Boost spirit x3 元组成员

c++ - 在不更改接口(interface)的情况下向对象添加功能

c++ - 在进程崩溃时调用 VS 调试器 vista-win8k

c++ - 在 Windows 10 和 Visual Studio Community 2019 下使用 boost with Bazel

c++ - 我的代码是否等同于 Boost.Asio 教程中给出的代码?

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