当使用std :: function w / std :: bind时,EXC_BAD_ACCESS [英] EXC_BAD_ACCESS when using std::function w/ std::bind

查看:142
本文介绍了当使用std :: function w / std :: bind时,EXC_BAD_ACCESS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用带std :: bind的std :: function升级到XCode 5后,似乎生成EXC_BAD_ACCESS异常。它看起来好像__base指针在std :: function的实现内部结束为null,导致访问不良,但我不清楚为什么会是这样。有没有人对我做错了什么?

After upgrading to XCode 5 using std::function with std::bind appears to be generating EXC_BAD_ACCESS exceptions. It looks as if the __base pointer inside the implementation of std::function ends up being null, resulting in the bad access, but I'm not clear on why that would be the case. Does anyone have an insight into either what I'm doing wrong?

这里是解释问题的示例代码。

Here is sample code that illustrates the problem.

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 a std :: function crashes with Clang )where the solution simply was to从XCode 5.0.1升级到XCode 5.0.2。

It seems that this may be a bug that has been fixed. I had a similar issue (std::bind to a std::function crashes with Clang) where the solution simply was to upgrade from XCode 5.0.1 to XCode 5.0.2.

我试过你的代码,它似乎与XCode 5.0.2(没有尝试过5.0.1 )。

I tried your code and it seems to work fine with XCode 5.0.2 (have not tried with 5.0.1).

这篇关于当使用std :: function w / std :: bind时,EXC_BAD_ACCESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆