我有一个函数void __fastcall ClassName::FunctionName()
。
我想使用 boost::bind 创建一个指向该函数的 boost 函数。这可能吗?编写 boost::bind(&ClassName::FunctionName, this)
会产生编译错误“必须调用成员函数或其地址”。
一个可能的解决方法是创建一个包装函数,但这是不可取的,因为它会创建无用的额外代码:
void ClassName::FunctionName2(){
FunctionName();
}
...
boost::bind(&ClassName::FunctionName2, this);
最佳答案
这可以通过使用宏启用对 __fastcall
的支持来解决:
#define BOOST_MEM_FN_ENABLE_FASTCALL
#include <boost/bind.hpp>
此后,boost::bind 语法将按预期工作。
这是一个不可移植的扩展,因此默认情况下不启用。 Boost::bind documentation .
关于c++ - 将 boost::bind 与 __fastcall 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35570737/