Listing 7

#include <functional>
#include <iostream>
#include <memory>
using std::cout;
using std::tr1::mem_fn; using std::tr1::shared_ptr;

struct C
  {
  C(int ii) : i(ii) {}
  void show() const {cout << i << '\n'; }
  int i;
  };
template <class Mfn>
void demo(Mfn mfn)
  {
  shared_ptr<C> sp(new C(3));
  mfn(*sp);      // call with reference to object
  mfn(sp.get()); // call with pointer to object
  mfn(sp);       // call with shared_ptr that points to object
  }
int main()
  {
  demo(mem_fn(&C::show));
  return 0;
  }