我的语法部分如下:
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/