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

相关问题