2011-05-12 39 views
1

我有問題將成員函數指針傳遞給gcc上的模板化成員函數。有誰知道如何修改下面的代碼讓gcc接受我想要做的事情?有問題將成員函數指針傳遞給gcc上的模板化成員函數

test.cpp:40: error: 'memFn' was not declared in this scope 
test.cpp:40: error: expected primary-expression before '(' token 
test.cpp:40: error: expected identifier before '*' token 
test.cpp:40: error: expected '(' before '*' token 
test.cpp:40: error: 'memFn' was not declared in this scope 
test.cpp:40: error: variable or field 'Execute' declared void 

GCC的版本,我用的是4.4.2:

class Foo 
{ 
public: 
    template <class C, class R> 
    void Execute(R(typename C::*memFn)()) 
    { 
    } 
}; 

我試圖編譯代碼時,遇到下列錯誤。

非常感謝您的幫助!

回答

5

你不需要typename。刪除它,它應該工作。 (我在gcc 4.3.2上測試過)。

+0

謝謝。我不知道我爲什麼最初把它放在那裏。 MSVS當然不在乎。 Kevin 2011-05-12 20:21:14