title: C++ 11: Calling a C++ function periodically
body: <p>I have put together a simple c++ timer class that is supposed to call a given function periodically from various examples on SO as follows:</p>
  
  <pre><code>#include &lt;functional&gt;
  #include &lt;chrono&gt;
  #include &lt;future&gt;
  #include &lt;cstdio&gt;
  
  class CallBackTimer
  {
  public:
      CallBackTimer()
      :_execute(false)
      {}
  
      void start(int interval, std::function&lt;void(void)&gt; func)
      {
          _execute = true;
          std::thread([&amp;]()
          {
              while (_execute) {
                  func();                   
                  std::this_thread::sleep_for(
                  std::chrono::milliseconds(interval));
              }
          }).detach();
      }
  
      void stop()
      {
          _execute = false;
      }
  
  private:
      bool            _execute;
  };
  </code></pre>
  
  <p>Now I want to call this from a C++ class as followsL</p>
  
  <pre><code>class Processor()
  {
      void init()
      {
           timer.start(25, std::bind(&amp;Processor::process, this));
      }
  
      void process()
      {
          std::cout &lt;&lt; "Called" &lt;&lt; std::endl;
      }
  };
  </code></pre>
  
  <p>However, this calls with the error </p>
  
  <pre><code>terminate called after throwing an instance of 'std::bad_function_call'
  what():  bad_function_call
  </code></pre>