title: Boost thread can't create thread with class member function
body: <p><strong>Solved</strong>
  <br> I tried to create boost thread with class member function, but i got errors. Could I do this on C++? How can I solve it?</p>
  
  <p>Source code isn't full because it is long.</p>
  
  <p>P.S. My function doesn't take parameters. And i doesn't try to work with thread pointer. So it isn't duplicate.</p>
  
  <p><strong>P.S.S I solved this problem when replace boost::thread <code>scheduler_thread_test(scheduler::waiter_function);</code> with <code>boost::thread scheduler_thread_test(&amp;scheduler::waiter_function, this);</code>
  <br>I understand why i need '&amp;' symbol?</strong></p>
  
  <p>Platform: Linux amd64</p>
  
  <p>scheduler.hpp</p>
  
  <pre><code>#ifndef SCHEDULER_H
  #define SCHEDULER_H
  
  #include &lt;boost/date_time/posix_time/posix_time.hpp&gt;
  #include &lt;boost/thread.hpp&gt;
  #include &lt;functional&gt;
  #include &lt;vector&gt;
  
  namespace schelduler{
      using namespace schelduler;
      using namespace boost::posix_time;
  
      class scheduler{
          private:
              //std::vector&lt;task_timepoint*&gt; tasks;
              boost::thread *scheduler_thread;
  
              void waiter_function();
          public:
              void add_task(task_timepoint* task);
              scheduler();
      };
  }
   #endif
  </code></pre>
  
  <p>scheduler.cpp</p>
  
  <pre><code>#include "scheduler.hpp"
  
  using namespace schelduler;
  using namespace boost::posix_time;
  
  
  scheduler::scheduler()
  {
      //this-&gt;scheduler_thread = new std::thread(this-&gt;waiter_function);
      boost::thread scheduler_thread_test(scheduler::waiter_function);
      this-&gt;scheduler_thread-&gt;detach();
  }
  </code></pre>
  
  <p>make log:</p>
  
  <pre><code>Scanning dependencies of target Refregiration_Telemetry-Device
  [ 50%] Building CXX object CMakeFiles/Refregiration_Telemetry-Device.dir/src/main.cpp.o
  [100%] Building CXX object CMakeFiles/Refregiration_Telemetry-Device.dir/src/scheduler.cpp.o
  /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp: In constructor ‘schelduler::scheduler::scheduler()’:
  /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:44:67: error: no matching function for call to ‘boost::thread::thread(&lt;unresolved overloaded function type&gt;)’
       boost::thread scheduler_thread_test(scheduler::waiter_function);
                                                                     ^
  /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:44:67: note: candidates are:
  In file included from /usr/include/boost/thread/thread_only.hpp:22:0,
                   from /usr/include/boost/thread/thread.hpp:12,
                   from /usr/include/boost/thread.hpp:13,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/include/scheduler.hpp:5,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:1:
  /usr/include/boost/thread/detail/thread.hpp:443:9: note: template&lt;class F, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9&gt; boost::thread::thread(F, A1, A2, A3, A4, A5, A6, A7, A8, A9)
           thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7,A8 a8,A9 a9):
           ^
  /usr/include/boost/thread/detail/thread.hpp:443:9: note:   template argument deduction/substitution failed:
  /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:44:67: note:   candidate expects 10 arguments, 1 provided
       boost::thread scheduler_thread_test(scheduler::waiter_function);
                                                                     ^
  In file included from /usr/include/boost/thread/thread_only.hpp:22:0,
                   from /usr/include/boost/thread/thread.hpp:12,
                   from /usr/include/boost/thread.hpp:13,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/include/scheduler.hpp:5,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:1:
  /usr/include/boost/thread/detail/thread.hpp:436:9: note: template&lt;class F, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8&gt; boost::thread::thread(F, A1, A2, A3, A4, A5, A6, A7, A8)
           thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7,A8 a8):
           ^
  /usr/include/boost/thread/detail/thread.hpp:436:9: note:   template argument deduction/substitution failed:
  /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:44:67: note:   candidate expects 9 arguments, 1 provided
       boost::thread scheduler_thread_test(scheduler::waiter_function);
                                                                     ^
  In file included from /usr/include/boost/thread/thread_only.hpp:22:0,
                   from /usr/include/boost/thread/thread.hpp:12,
                   from /usr/include/boost/thread.hpp:13,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/include/scheduler.hpp:5,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:1:
  /usr/include/boost/thread/detail/thread.hpp:429:9: note: template&lt;class F, class A1, class A2, class A3, class A4, class A5, class A6, class A7&gt; boost::thread::thread(F, A1, A2, A3, A4, A5, A6, A7)
           thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6,A7 a7):
           ^
  /usr/include/boost/thread/detail/thread.hpp:429:9: note:   template argument deduction/substitution failed:
  /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:44:67: note:   candidate expects 8 arguments, 1 provided
       boost::thread scheduler_thread_test(scheduler::waiter_function);
                                                                     ^
  In file included from /usr/include/boost/thread/thread_only.hpp:22:0,
                   from /usr/include/boost/thread/thread.hpp:12,
                   from /usr/include/boost/thread.hpp:13,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/include/scheduler.hpp:5,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:1:
  /usr/include/boost/thread/detail/thread.hpp:422:9: note: template&lt;class F, class A1, class A2, class A3, class A4, class A5, class A6&gt; boost::thread::thread(F, A1, A2, A3, A4, A5, A6)
           thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5,A6 a6):
           ^
  /usr/include/boost/thread/detail/thread.hpp:422:9: note:   template argument deduction/substitution failed:
  /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:44:67: note:   candidate expects 7 arguments, 1 provided
       boost::thread scheduler_thread_test(scheduler::waiter_function);
                                                                     ^
  In file included from /usr/include/boost/thread/thread_only.hpp:22:0,
                   from /usr/include/boost/thread/thread.hpp:12,
                   from /usr/include/boost/thread.hpp:13,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/include/scheduler.hpp:5,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:1:
  /usr/include/boost/thread/detail/thread.hpp:415:9: note: template&lt;class F, class A1, class A2, class A3, class A4, class A5&gt; boost::thread::thread(F, A1, A2, A3, A4, A5)
           thread(F f,A1 a1,A2 a2,A3 a3,A4 a4,A5 a5):
           ^
  /usr/include/boost/thread/detail/thread.hpp:415:9: note:   template argument deduction/substitution failed:
  /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:44:67: note:   candidate expects 6 arguments, 1 provided
       boost::thread scheduler_thread_test(scheduler::waiter_function);
                                                                     ^
  In file included from /usr/include/boost/thread/thread_only.hpp:22:0,
                   from /usr/include/boost/thread/thread.hpp:12,
                   from /usr/include/boost/thread.hpp:13,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/include/scheduler.hpp:5,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:1:
  /usr/include/boost/thread/detail/thread.hpp:408:9: note: template&lt;class F, class A1, class A2, class A3, class A4&gt; boost::thread::thread(F, A1, A2, A3, A4)
           thread(F f,A1 a1,A2 a2,A3 a3,A4 a4):
           ^
  /usr/include/boost/thread/detail/thread.hpp:408:9: note:   template argument deduction/substitution failed:
  /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:44:67: note:   candidate expects 5 arguments, 1 provided
       boost::thread scheduler_thread_test(scheduler::waiter_function);
                                                                     ^
  In file included from /usr/include/boost/thread/thread_only.hpp:22:0,
                   from /usr/include/boost/thread/thread.hpp:12,
                   from /usr/include/boost/thread.hpp:13,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/include/scheduler.hpp:5,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:1:
  /usr/include/boost/thread/detail/thread.hpp:401:9: note: template&lt;class F, class A1, class A2, class A3&gt; boost::thread::thread(F, A1, A2, A3)
           thread(F f,A1 a1,A2 a2,A3 a3):
           ^
  /usr/include/boost/thread/detail/thread.hpp:401:9: note:   template argument deduction/substitution failed:
  /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:44:67: note:   candidate expects 4 arguments, 1 provided
       boost::thread scheduler_thread_test(scheduler::waiter_function);
                                                                     ^
  In file included from /usr/include/boost/thread/thread_only.hpp:22:0,
                   from /usr/include/boost/thread/thread.hpp:12,
                   from /usr/include/boost/thread.hpp:13,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/include/scheduler.hpp:5,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:1:
  /usr/include/boost/thread/detail/thread.hpp:394:9: note: template&lt;class F, class A1, class A2&gt; boost::thread::thread(F, A1, A2)
           thread(F f,A1 a1,A2 a2):
           ^
  /usr/include/boost/thread/detail/thread.hpp:394:9: note:   template argument deduction/substitution failed:
  /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:44:67: note:   candidate expects 3 arguments, 1 provided
       boost::thread scheduler_thread_test(scheduler::waiter_function);
                                                                     ^
  In file included from /usr/include/boost/thread/thread_only.hpp:22:0,
                   from /usr/include/boost/thread/thread.hpp:12,
                   from /usr/include/boost/thread.hpp:13,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/include/scheduler.hpp:5,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:1:
  /usr/include/boost/thread/detail/thread.hpp:388:9: note: template&lt;class F, class A1&gt; boost::thread::thread(F, A1, typename boost::disable_if&lt;boost::thread_detail::is_convertible&lt;F&amp;, boost::thread_attributes&gt;, boost::thread::dummy*&gt;::type)
           thread(F f,A1 a1,typename disable_if&lt;boost::thread_detail::is_convertible&lt;F&amp;,thread_attributes &gt;, dummy* &gt;::type=0):
           ^
  /usr/include/boost/thread/detail/thread.hpp:388:9: note:   template argument deduction/substitution failed:
  /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:44:67: note:   candidate expects 3 arguments, 1 provided
       boost::thread scheduler_thread_test(scheduler::waiter_function);
                                                                     ^
  In file included from /usr/include/boost/thread/thread_only.hpp:22:0,
                   from /usr/include/boost/thread/thread.hpp:12,
                   from /usr/include/boost/thread.hpp:13,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/include/scheduler.hpp:5,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:1:
  /usr/include/boost/thread/detail/thread.hpp:337:9: note: boost::thread::thread(boost::thread&amp;&amp;)
           thread(BOOST_THREAD_RV_REF(thread) x)
           ^
  /usr/include/boost/thread/detail/thread.hpp:337:9: note:   no known conversion for argument 1 from ‘&lt;unresolved overloaded function type&gt;’ to ‘boost::thread&amp;&amp;’
  /usr/include/boost/thread/detail/thread.hpp:272:9: note: template&lt;class F&gt; boost::thread::thread(const attributes&amp;, F&amp;&amp;)
           thread(attributes const&amp; attrs, BOOST_THREAD_RV_REF(F) f):
           ^
  /usr/include/boost/thread/detail/thread.hpp:272:9: note:   template argument deduction/substitution failed:
  /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:44:67: note:   cannot convert ‘((schelduler::scheduler*)this)-&gt;schelduler::scheduler::waiter_function’ (type ‘&lt;unresolved overloaded function type&gt;’) to type ‘const attributes&amp; {aka const boost::thread_attributes&amp;}’
       boost::thread scheduler_thread_test(scheduler::waiter_function);
                                                                     ^
  In file included from /usr/include/boost/thread/thread_only.hpp:22:0,
                   from /usr/include/boost/thread/thread.hpp:12,
                   from /usr/include/boost/thread.hpp:13,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/include/scheduler.hpp:5,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:1:
  /usr/include/boost/thread/detail/thread.hpp:262:18: note: boost::thread::thread(F&amp;&amp;) [with F = void (schelduler::scheduler::*)()]
           explicit thread(BOOST_THREAD_RV_REF(F) f
                    ^
  /usr/include/boost/thread/detail/thread.hpp:262:18: note:   no known conversion for argument 1 from ‘&lt;unresolved overloaded function type&gt;’ to ‘void (schelduler::scheduler::*&amp;&amp;)()’
  /usr/include/boost/thread/detail/thread.hpp:246:9: note: boost::thread::thread()
           thread() BOOST_NOEXCEPT;
           ^
  /usr/include/boost/thread/detail/thread.hpp:246:9: note:   candidate expects 0 arguments, 1 provided
  In file included from /usr/include/boost/thread/thread_only.hpp:22:0,
                   from /usr/include/boost/thread/thread.hpp:12,
                   from /usr/include/boost/thread.hpp:13,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/include/scheduler.hpp:5,
                   from /home/dm3ch/Workspace/Refregiration_Telemetry/Device/src/scheduler.cpp:1:
  /usr/include/boost/thread/detail/thread.hpp:193:18: note: boost::thread::thread(boost::detail::thread_data_ptr)
           explicit thread(detail::thread_data_ptr data);
                    ^
  /usr/include/boost/thread/detail/thread.hpp:193:18: note:   no known conversion for argument 1 from ‘&lt;unresolved overloaded function type&gt;’ to ‘boost::detail::thread_data_ptr {aka boost::shared_ptr&lt;boost::detail::thread_data_base&gt;}’
  make[2]: *** [CMakeFiles/Refregiration_Telemetry-Device.dir/src/scheduler.cpp.o] Error 1
  make[1]: *** [CMakeFiles/Refregiration_Telemetry-Device.dir/all] Error 2
  make: *** [all] Error 2
  </code></pre>