小编dav*_*sti的帖子

使用std :: shared_ptr和std :: thread编译错误

我正在尝试使用shared_ptrfrom类启动线程Test,我收到此错误:

/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>&'

示例代码:

    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
Run Code Online (Sandbox Code Playgroud)

注意:在使用VS2013的Windows中,第一个示例工作正常.

c++ c++11

7
推荐指数
1
解决办法
458
查看次数

标签 统计

c++ ×1

c++11 ×1