【发布时间】:2011-03-27 16:25:34
【问题描述】:
boost::spirit 文档有这个重要警告
为 Spirit.Qi 编写语义动作有多种方式:使用 普通函数,
Boost.Bind、Boost.Lambda或Phoenix。后者 三允许您使用特殊的占位符来控制参数 展示位置(_1、_2等)。这些库中的每一个都有自己的 占位符的实现,都在不同的命名空间中。你有 确保不要将占位符与它们不属于的库混合 并且在编写语义动作时不要使用不同的库。一般来说,对于
Boost.Bind,使用::_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
]
如何修复这个编译器错误?
【问题讨论】:
标签: c++ boost boost-spirit