0

我面臨模板成員函數指針的問題。代碼如下所示。模板Fn指針錯誤C2146:語法錯誤:缺少';'之前標識符

#include <String> 
#include <iostream> 
template<typename T> 
struct method_ptr 
{ 
    typedef void (T::*Function)(std::string&); 
}; 

template <class T> 
class EventHandler 
{ 
private: 
    method_ptr<T>::Function m_PtrToCapturer; 
}; 

E:\ EventHandler.h(13):

error C2146: syntax error : missing ';' before identifier 'm_PtrToCapturer' 

我面對這個錯誤。

即使我使用

method_ptr<EventHandler>::Function m_PtrToCapturer; 

爲成員變量我如上得到同樣的錯誤。

+0

可能的重複[正式,什麼是typename?](http://stackoverflow.com/questions/1600936/officially-what-is-typename-for) – Constructor

+0

重複的http://stackoverflow.com/questions/21863194/resolved-templated-function-pointer-in-c/21890444#21890444 – TechTotie

回答

0

我不知道你使用哪個編譯器。我使用GCC編譯它。它表明'typename'放在m_PtrToCapturer的定義之前。

+0

我正在使用cl編譯器Visual Studio 2008 .. – TechTotie

相關問題