rav*_*int 5 c++ boost boost-spirit
该boost::spirit
文档有重要的警示
有不同的方式来写语义动作为Spirit.Qi:使用普通函数
Boost.Bind
,Boost.Lambda
或Phoenix
.后三种允许你使用特殊的占位符来控制参数配置(_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;
};
Run Code Online (Sandbox Code Playgroud)
请注意使用 ::_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
]
Run Code Online (Sandbox Code Playgroud)
如何修复此编译器错误?
你是否可以using namespace boost::spirit;
在该文件的顶部写一个地方?因为如果是,精神和绑定占位符现在都在全局命名空间中.直接使用qi::
可能会支持我的假设,但这可能也很简单namespace qi = boost::spirit::qi
.