boost:bind 和两个具有相同名称和参数计数的方法

boost:bind and two methods with the same name and args count

本文关键字:参数 方法 bind boost 两个      更新时间:2023-10-16

我有一个有两个方法的类

bool Syntax::removeTarget( CommandParam &params );

bool Syntax::removeTarget( const std::string & targetId );

如何绑定第二种方法? boost::bind(&Syntax::removeTarget, this, _1)不起作用。

要消除重载的歧义,您必须将它们强制转换(或以其他方式强制)为正确的类型。这应该有效:

boost::bind(static_cast<bool (Syntax::*)(const std::string&)>(&Syntax::removeTarget), this, _1);