title: Member function call on shared_ptr through member function pointer in template
body: <p>This is a template function that takes a pointer (or a pointer like object) and a member function:</p>
  
  <pre><code>template &lt;typename Ptr, typename MemberFunctor&gt;
  int example(Ptr ptr, MemberFunctor func )
  {
      return (ptr-&gt;*func)();
  }
  </code></pre>
  
  <p>If works when used with ordinary pointer:</p>
  
  <pre><code>struct C
  {
      int getId() const { return 1; }
  };
  
  C* c = new C;
  example(c, &amp;C::getId);    // Works fine
  </code></pre>
  
  <p>But it does not work with smart pointers:</p>
  
  <pre><code>std::shared_ptr&lt;C&gt; c2(new C);
  example(c2, &amp;C::getId);
  </code></pre>
  
  <p>Error message:</p>
  
  <pre><code>error: C2296: '-&gt;*' : illegal, left operand has type 'std::shared_ptr&lt;C&gt;'
  </code></pre>
  
  <p>Why? and How to make something that works with both?</p>