title: Using t( *this ) results RuntimeError, while t( std::ref( *this ) does not
body: <p>I have the following example: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;functional&gt;
  
  struct Tmr {
      typedef std::function&lt;void(void)&gt; Callback;
      Callback cb;
  
      Tmr(Callback cb_) :
          cb( cb_ )
      {
      }
  
      void timeout()
      {
          cb();
      }
  };
  
  struct Obj {
      struct Tmr t;
  
      Obj() :
          t( std::ref( *this ) )
      {
      }
  
      void operator () ()
      {
          std::cout &lt;&lt; __func__ &lt;&lt; '\n';
      }
  };
  
  int main(int argc, char *argv[])
  {
      Obj o;
  
      o.t.timeout();
  
      return 0;
  }
  </code></pre>
  
  <p>This runs fine, but initially I had the constructor of <code>Obj</code> as:</p>
  
  <pre><code>Obj() :
      t( *this )
  </code></pre>
  
  <p>Which results in a runtime error. I guess this is because only a reference to the member function is stored in my callback, and not the object to call the member on.</p>
  
  <p>What I don't understand is what <code>std::ref</code> does when I do <code>Obj() : t(std::ref(*this))</code> and why this makes the program work. Can anyone shed some light on what's going on and how it works ?</p>