错误:<token之前的预期模板名称

use*_*533 1 c++ templates

您好我收到以下错误

templateatt.cpp:4:32: error: expected template-name before ‘<‘ token
templateatt.cpp:4:32: error: expected â{â before ‘<‘ token
templateatt.cpp:4:32: error: expected unqualified-id before ‘<‘ token
Run Code Online (Sandbox Code Playgroud)

当我编译以下cpp文件时:

    #include<iostream>

    template <class R, class T>
    class mem_fun_t: unary_function<T*, R> {
      R (T::*pmf)();
    public:
      explicit mem_fun_t(R (T::*p)()):pmf(p){}
      R operator() (T *p) const { return (p->*pmf()); }
    };

    int main() {
      return 0;
    }
Run Code Online (Sandbox Code Playgroud)

任何帮助都会很棒.我被困在这里.

Jos*_*eld 7

不要忘记#include <functional>获得unary_function然后用它来获得资格std::unary_function.