我只是在 Bjorn Karlsson 的“Beyond the Standard Library”中输入一些解释活页夹如何工作的代码。我正在使用 Visual Studio 2010 Express,并且出现缺少分号的错误。
这一点似乎很好:
// template for a simple function object
/////////////////////////////////////////////////////////////////////////////
template<typename R, typename T, typename Arg>
  class simple_bind_t {
    typedef R (T::*fn) (Arg);  // fn defines a type - a ptr to member fn
                               // of object T, returning an R, and taking Arg
    fn _fn;                    // the function object owns a pointer to function.
    T  _t;                     // it also owns an object of type T.
  public:
    simple_bind_t(fn f, const T& t):
             _fn(fn), _t(t) {} // instantiate mber variables
    R operator()(Arg& a) 
    { 
      return (_t->_fn)(a);    // invoke the member function on t, pass a as an arg.
    }
  };
所以那一点都很好。但是当我去定义创建函数对象的实际函数时,(见下面的代码片段),我在行的下方得到一条小R红线R (T::*fn)(Arg),。当我将鼠标移到上面时,它会显示 - Error: expected a ';')。
template <class R, class T, class Arg> 
   simple_bind_t<R,T,Arg> simple_bind (
     R (T::*fn)(Arg),                     
     const T& t,
     const placeholder&)
   { return simple_bind_t<R,T,Arg>(fn,t); } // construct an object of simple_bind_t<R,T,Arg>
                                        // pass it pointer to the member function, fn
                                        // and the object of type T to bind to, t
谁能发现语法错误在哪里?