【问题标题】:No matching function for call error for Qi semantic actionQi语义动作的调用错误没有匹配函数
【发布时间】:2013-12-31 18:28:10
【问题描述】:

我有一部分语法如下:

typedef SemanticActions< IterType > SemanticActionsType;

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

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

以及对应的语义动作类:

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;
    }

我可以从 int_ 令牌调用“打印”函数,但无法从 string_ 令牌调用 new_component_name。

我收到以下错误: boost/include/boost/bind/bind.hpp:397:9: No matching function for call to object of type 'const boost::_mfi::cmf2 >, std:: __1::__wrap_iter, std::__1::__wrap_iter >'

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

【问题讨论】:

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


    【解决方案1】:

    您需要使用 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 语义动作的许多不稳定问题(有时甚至需要在最近的编译器上编译示例)。

    【讨论】:

    • 正如您 just realized 一样,lit 根本没有公开属性,所以 _2 一开始就被误导了。当然,这不会使这个答案出错。我会争辩说,如果这个答案对您没有帮助,那么问题就是错误的:)。提示:您需要确保string_ 暴露std::stringqi::rule&lt;It, std::string()&gt;,注意括号!)。
    猜你喜欢
    • 2013-05-05
    • 2012-12-28
    • 2015-03-31
    • 1970-01-01
    • 2016-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多