5

boost::spirit文档有这个重要的警告

为 Spirit.Qi 编写语义动作有多种方式:使用普通函数、Boost.BindBoost.LambdaPhoenix。后三个允许您使用特殊的占位符来控制参数的放置(_1_2等)。这些库中的每一个都有自己的占位符实现,都在不同的命名空间中。您必须确保不要将占位符与它们不属于的库混合使用,并且在编写语义操作时不要使用不同的库。

通常,for Boost.Bind、use ::_1::_2等(是的,这些占位符是在全局命名空间中定义的)。

用于Boost.Lambda使用命名空间中定义的占位符boost::lambda

对于使用 Phoenix 编写的语义操作,请使用命名空间中定义的占位符boost::spirit。请注意,为了您的方便,所有现有的占位符也可以从命名空间获得boost::spirit::qi

文档

好的,所以我写了这段代码

template <typename Iterator>
struct ruleset_grammar : qi::grammar<Iterator>
{
    template <typename TokenDef>
    ruleset_grammar(TokenDef const& tok)
      : ruleset_grammar::base_type(start)
    {

        start =  *(  tok.set_name [ boost::bind( &cRuleSet::setName, &theRuleSet, ::_1 ) ]
                  )
              ;
    }

    qi::rule<Iterator> start;
};

请注意使用::_1

但是,我仍然收到此编译器错误

c:\documents and settings\james\spirit_test.cpp(138) : error C2872: '_1' : ambiguous symbol
        could be 'c:\program files\boost\boost_1_44\boost\spirit\home\support\argument.hpp(124) : const boost::phoenix::actor<Eval> boost::spirit::_1'
        with
        [
            Eval=boost::spirit::argument<0>
        ]
        or       'c:\program files\boost\boost_1_44\boost\bind\placeholders.hpp(43) : boost::arg<I> `anonymous-namespace'::_1'
        with
        [
            I=1
        ]

如何修复此编译器错误?

4

1 回答 1

7

using namespace boost::spirit;您是否可能在该文件顶部的某个地方写了一个?因为如果是,那么精神和绑定占位符现在都在全局命名空间中。直接使用qi::可能支持我的假设,但这也可能是一个简单的namespace qi = boost::spirit::qi.

于 2011-03-27T16:39:55.620 回答