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

error: expected template-name before < token

本文关键字:lt 令牌 错误      更新时间:2023-10-16

你好,我得到以下错误

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

当我编译以下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;
    }

任何帮助都会很好。

不要忘记用#include <functional>来得到unary_function,然后用std::unary_function来限定它