Compiler error using std::shared

I'm trying to start thread using a shared_ptr from class Test , and I get this error:

/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/functional:559:2: note: no known conversion for argument 1 from 'std::shared_ptr<Test>' to 'std::shared_ptr<Test>&'

Example Code:

    std::shared_ptr<Test> test = std::make_shared<Test>();
    std::thread th(&Test::run, test); // Compiler error


    Test* test2 = new Test;
    std::thread th(&Test::run, test2); // okay

Note: In windows with VS2013 works fine the first example.


This looks like a bug in the gcc version you're using, as it should work. And looking at http://ideone.com/GOQ35M it does work

As a workaround, you can try

std::shared_ptr<Test> test = std::make_shared<Test>();
std::thread th(std::bind(&Test::run, test))
链接地址: http://www.djcxy.com/p/20756.html

上一篇: 使用ORMLite DAO作为ContentProvider

下一篇: 编译器错误使用std :: shared