title: How to bind function to an object by reference?
body: <p>I have the following code to bind a member function to an instance of the class:</p>
  
  <pre><code>class Foo {
  public:
      int i;
      void test() {
          std::cout &lt;&lt; i &lt;&lt; std::endl;
      }
  };
  
  int main() {
      Foo f;
      f.i = 100;
      auto func = std::bind(&amp;Foo::test, std::forward&lt;Foo&gt;(f));
      f.i = 1000;
      func();
  }
  </code></pre>
  
  <p>But the <code>std::bind</code> statement does not bind to <code>f</code> by reference. Calling <code>func</code> prints "100" instead of "1000" which is what I want.</p>
  
  <p>However, If I change the statement to take a pointer it works.</p>
  
  <pre><code>auto func = std::bind(&amp;Foo::test, &amp;f);
  </code></pre>
  
  <p>But this is passing <code>f</code> by pointer by my understanding, and as I thought <code>std::bind</code> takes an r-value reference <code>Arg&amp;&amp;</code> (as shown <a href="http://en.cppreference.com/w/cpp/utility/functional/bind" rel="noreferrer">here</a>) how can this work?</p>
  
  <p>Can someone please explain this?</p>