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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With