Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating boost::thread with an std::shared_ptr object instance
    primarykey
    data
    text
    <p>I have the following two code segments. The first block compiles and works as expected. However the second block does not compile. </p> <p>My question is, given the code below what is the correct syntax when trying to create a thread based on an instance of an object that is being proxied by a shared_ptr?</p> <pre><code>#include &lt;iostream&gt; #include &lt;new&gt; #include &lt;memory&gt; #include &lt;boost/thread.hpp&gt; struct foo { void boo() {} }; int main() { //This works { foo* fptr = new foo; boost::thread t(&amp;foo::boo,fptr); t.join(); delete fptr; } //This doesn't work { std::shared_ptr&lt;foo&gt; fptr(new foo); boost::thread t(&amp;foo::boo,fptr); t.join(); } return 0; } </code></pre> <p>The compiler error:</p> <pre><code>Error 5 error C2784: 'T *boost::get_pointer(T *)' : could not deduce template argument for 'T *' from 'std::tr1::shared_ptr&lt;_Ty&gt;' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest Error 3 error C2784: 'T *boost::get_pointer(const std::auto_ptr&lt;_Ty&gt; &amp;)' : could not deduce template argument for 'const std::auto_ptr&lt;_Ty&gt; &amp;' from 'std::tr1::shared_ptr&lt;_Ty&gt;' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest Error 4 error C2784: 'T *boost::get_pointer(const std::auto_ptr&lt;_Ty&gt; &amp;)' : could not deduce template argument for 'const std::auto_ptr&lt;_Ty&gt; &amp;' from 'std::tr1::shared_ptr&lt;_Ty&gt;' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest Error 8 error C2784: 'T *boost::get_pointer(const boost::shared_ptr&lt;X&gt; &amp;)' : could not deduce template argument for 'const boost::shared_ptr&lt;X&gt; &amp;' from 'std::tr1::shared_ptr&lt;_Ty&gt;' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest Error 9 error C2784: 'T *boost::get_pointer(const boost::shared_ptr&lt;X&gt; &amp;)' : could not deduce template argument for 'const boost::shared_ptr&lt;X&gt; &amp;' from 'std::tr1::shared_ptr&lt;_Ty&gt;' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest Error 1 error C2784: 'T *boost::get_pointer(const boost::scoped_ptr&lt;T&gt; &amp;)' : could not deduce template argument for 'const boost::scoped_ptr&lt;T&gt; &amp;' from 'std::tr1::shared_ptr&lt;_Ty&gt;' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest Error 2 error C2784: 'T *boost::get_pointer(const boost::scoped_ptr&lt;T&gt; &amp;)' : could not deduce template argument for 'const boost::scoped_ptr&lt;T&gt; &amp;' from 'std::tr1::shared_ptr&lt;_Ty&gt;' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest Error 6 error C2784: 'T *boost::get_pointer(const boost::reference_wrapper&lt;T&gt; &amp;)' : could not deduce template argument for 'const boost::reference_wrapper&lt;T&gt; &amp;' from 'std::tr1::shared_ptr&lt;_Ty&gt;' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest Error 7 error C2784: 'T *boost::get_pointer(const boost::reference_wrapper&lt;T&gt; &amp;)' : could not deduce template argument for 'const boost::reference_wrapper&lt;T&gt; &amp;' from 'std::tr1::shared_ptr&lt;_Ty&gt;' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest Error 10 error C2784: 'T *boost::get_pointer(const boost::intrusive_ptr&lt;T&gt; &amp;)' : could not deduce template argument for 'const boost::intrusive_ptr&lt;T&gt; &amp;' from 'std::tr1::shared_ptr&lt;_Ty&gt;' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest Error 11 error C2784: 'T *boost::get_pointer(const boost::intrusive_ptr&lt;T&gt; &amp;)' : could not deduce template argument for 'const boost::intrusive_ptr&lt;T&gt; &amp;' from 'std::tr1::shared_ptr&lt;_Ty&gt;' c:\program files (x86)\boost\boost_1_47\boost\bind\mem_fn_template.hpp 40 1 htest </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload