title: Encapsulate thread function with boost bind
body: <p>I am currently creating boost::threads like this:</p>
  
  <pre><code>  boost::thread m_myThread; //member variable
    //...
    m_myThread = boost::thread(boost::bind(&amp;MyClass::myThreadFunction, this));
  </code></pre>
  
  <p>This will start a thread which executes a member function "myThreadFunction".</p>
  
  <p>I would like to encapsulate the starting of a new thread and use something like</p>
  
  <pre><code>boost::thread m_myThread; //member variable
  //...
  startAThread(&amp;m_myThread, boost::bind(&amp;MyClass::myThreadFunction, this), 123 /*some int argument*/);
  </code></pre>
  
  <p>I thought I could implement "startAThread" like this:</p>
  
  <pre><code>namespace internal
  {
      template &lt;typename Callable&gt;
      void threadhelper(Callable func, int x)
      {
          doSomething(x);
          func();
      }
  }
  template &lt;typename Callable&gt;
  void startAThread(boost::thread* threadToCreate, Callable func, int x)
  {
  
      *threadToCreate = boost::thread(boost::bind(internal::threadhelper&lt;Callable&gt;, func, x));
  }
  </code></pre>
  
  <p>However, this fails to compile with</p>
  
  <pre><code>usr/include/boost/bind/bind.hpp: In member function 'void boost::_bi::list2&lt;A1, A2&gt;::operator()(boost::_bi::type&lt;void&gt;, F&amp;, A&amp;, int) [with F = void (*)(boost::_bi::bind_t&lt;void, boost::_mfi::mf0&lt;void, MyClass&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;MyClass*&gt; &gt; &gt;, int), A = boost::_bi::list0, A1 = boost::_bi::bind_t&lt;void, boost::_mfi::mf0&lt;void, MyClass&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;MyClass*&gt; &gt; &gt;, A2 = boost::_bi::value&lt;int&gt;]':
  usr/include/boost/bind/bind_template.hpp:20:   instantiated from 'typename boost::_bi::result_traits&lt;R, F&gt;::type boost::_bi::bind_t&lt;R, F, L&gt;::operator()() [with R = void, F = void (*)(boost::_bi::bind_t&lt;void, boost::_mfi::mf0&lt;void, MyClass&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;MyClass*&gt; &gt; &gt;, int), L = boost::_bi::list2&lt;boost::_bi::bind_t&lt;void, boost::_mfi::mf0&lt;void, MyClass&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;MyClass*&gt; &gt; &gt;, boost::_bi::value&lt;int&gt; &gt;]'
  usr/include/boost/thread/detail/thread.hpp:61:   instantiated from 'void boost::detail::thread_data&lt;F&gt;::run() [with F = boost::_bi::bind_t&lt;void, void (*)(boost::_bi::bind_t&lt;void, boost::_mfi::mf0&lt;void, MyClass&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;MyClass*&gt; &gt; &gt;, int), boost::_bi::list2&lt;boost::_bi::bind_t&lt;void, boost::_mfi::mf0&lt;void, MyClass&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;MyClass*&gt; &gt; &gt;, boost::_bi::value&lt;int&gt; &gt; &gt;]'
  MyClass.cpp:160:   instantiated from here
  usr/include/boost/bind/bind.hpp:313: error: conversion from 'void' to non-scalar type 'boost::_bi::bind_t&lt;void, boost::_mfi::mf0&lt;void, MyClass&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;MyClass*&gt; &gt; &gt;' requested
  </code></pre>
  
  <p>What does this error mean? What's wrong with the code?</p>
  
  <p>Thanks a lot!</p>