EXC_BAD_ACCESS 当使用 std::function w/ std::bind 时
EXC_BAD_ACCESS when using std::function w/ std::bind
使用 std:
:function 和 std::bind 升级到 XCode 5 后,似乎产生了EXC_BAD_ACCESS异常。看起来 std::function 实现中的__base指针最终为 null,导致访问错误,但我不清楚为什么会这样。有没有人知道我做错了什么?
下面是说明该问题的示例代码。
struct A
{
void foo(bool b)
{
std::cout << b << std::endl;
}
void go()
{
// ok
auto a = std::bind(&A::foo, this, std::placeholders::_1);
a(true);
// ok
std::function<void(A*, bool)> b = std::bind(&A::foo, std::placeholders::_1, std::placeholders::_2);
b(this, true);
// ok
std::function<void(A*, bool)> c = std::bind(&A::foo, this, std::placeholders::_2);
c(this, true);
// EXC_BAD_ACCESS
std::function<void(bool)> f = std::bind(&A::foo, this, std::placeholders::_1);
f(true);
}
};
...
...
A a;
a.go();
似乎这可能是一个已修复的错误。我有一个类似的问题(std::bind to std::function 崩溃与 Clang),解决方案只是从 XCode 5.0.1 升级到 XCode 5.0.2。
我尝试了您的代码,它似乎在 XCode 5.0.2 中运行良好(尚未尝试过 5.0.1)。
相关文章:
- Confusion: decltype vs std::function
- 为什么 std::function 可以作为 std::not2 的参数?
- 'max'匹配'std::function<const int &(const int &, const int &)>'无过载
- 传递给std::function template的template参数究竟代表什么
- 绑定派生类方法C++从实例范围之外的分隔 std::function 变量调用
- 将函数包装器转换为 std::function
- 类型擦除的std::function与虚拟函数调用的开销
- C++ std::function 对于类 exept 的所有实例都是空的(只有 Visual2019 编译器问题)
- 如果模板没有可变参数,则 Lambda 被推导出为 std::function
- 将 lambda 表达式传递给 std::function in C++
- 模板类的部分模板专用化,如 std::function
- 可变参数模板参数扩展 类型为 std::function 的类成员
- 从 std::function in C++ 访问模板化 lambda
- 什么是 std::function::argument_type 的替代品?
- C++派生类重载函数(带有 std::function 参数)不可见
- 如何在 qi 符号表中使用 std::function
- 将 std::function 与模板一起使用
- C++ 事件管理器的回调,使用 std::function 和 std:bind 以及派生类作为参数
- 我需要在 std::function 上使用 unique_ptr 吗?
- 如何将函数指针从 std::function 传递到 Linux 克隆?