C++ 模板Fn指针错误C2146:语法错误:缺少'';前标识符
我面临模板成员函数指针的问题。代码如下所示C++ 模板Fn指针错误C2146:语法错误:缺少'';前标识符,c++,templates,function-pointers,member-function-pointers,member-variables,C++,Templates,Function Pointers,Member Function Pointers,Member Variables,我面临模板成员函数指针的问题。代码如下所示 #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&g
#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;
};
我面临着这个错误
即使我使用
method_ptr<EventHandler>::Function m_PtrToCapturer;
method_ptr::函数m_PtrToCapturer;
作为成员变量,我得到了与上面相同的错误。我不知道您使用的是哪种编译器。我使用GCC编译了它。它建议将“typename”放在m_PtrToCapturer的定义之前。可能重复的
method_ptr<EventHandler>::Function m_PtrToCapturer;