2013-04-10 68 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