c++ - 将 boost::bind 与 __fastcall 一起使用

标签 c++ boost c++builder-xe8

我有一个函数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/

相关文章:

python 2 - 为什么 'with' 在嵌入式 c 代码中的行为不同?

c++ - (C++) 函数未声明

c++ - asio : multiple pending async_read?

delphi - RAD Studio XE8 - 您无法设置属性。未找到 TCustomActionList 的实例

c++ - 如何访问单个 TListViewItem 上的文本按钮

c++ - 模态对话框打开时无法聚焦 Firemonkey 应用程序,除非单击模态对话框本身

c++ - 可以删除抽象类而不是子类吗?

c++ - C++ 中的狮身人面像 (Linux)

c++ - Boost::Intrusive 中 splay_multiset 的成员 Hook 实现

c++ - 什么是系统:80 error showing while trying to copy file content?