7

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.

4
  • 2
    This looks like a bug in the gcc version you're using. Does std::thread th(std::bind(&Test::run, test)) work any better (it might not, since they might use some common internal code). Commented May 30, 2014 at 20:32
  • How odd... Commented May 30, 2014 at 20:36
  • 1
    Doesn't work on GCC 4.7 but does work on 4.8. Commented May 30, 2014 at 20:48
  • 1
    gcc.gnu.org/bugzilla/show_bug.cgi?id=56505 Commented May 30, 2014 at 20:53

1 Answer 1

3

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))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.