2013-04-10 67 views
1

你好我收到以下错误错误:预期模板的名称前<令牌

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; 
    } 

任何帮助将是巨大的。我坚持这一点。

+1

编译器和我,我们都看不到'unary_function'的任何定义... – PlasmaHH 2013-04-10 11:10:49

回答

7

不要忘了#include <functional>得到unary_function,然后通过std::unary_function进行资格。

+0

很好,谢谢它现在的作品... – user1663533 2013-04-10 11:16:15

+0

@ user1663533好!我知道你还不能,但是不要忘记接受。谢谢。 :) – 2013-04-10 11:17:07