简体   繁体   English

模板Fn指针错误C2146:语法错误:缺少';' 在标识符之前

[英]Template Fn Pointer error C2146: syntax error : missing ';' before identifier

I am facing a problem with templated member function pointer. 我面临模板成员函数指针的问题。 The code is as shown below. 代码如下所示。

#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) : e:\\ EventHandler.h(13):

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

I am facing this error. 我正在面对这个错误。

Even If I use 即使我用

method_ptr<EventHandler>::Function m_PtrToCapturer;

as member variable I am getting same error as above. 作为成员变量,我遇到了与上面相同的错误。

I don't know which compiler you use. 我不知道您使用哪个编译器。 I compiled it using GCC. 我使用GCC进行了编译。 It suggests that 'typename' is put before the definition of m_PtrToCapturer. 它建议在“ m_PtrToCapturer”的定义之前放置“ typename”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误C2146:语法错误:缺少&#39;;&#39; 在标识符之前 - error C2146: syntax error : missing ';' before identifier 错误C2146:语法错误:在标识符&#39;A1&#39;之前缺少&#39;,&#39; - Error C2146: syntax error : missing ',' before identifier 'A1' 错误C2146:语法错误:缺少&#39;;&#39; 在标识符之前 - Error C2146: syntax error : missing ';' before identifier 错误C2146:语法错误:缺少&#39;;&#39; 在标识符&#39;ContextRecord&#39;之前 - error C2146: syntax error : missing ';' before identifier 'ContextRecord' 错误C2146:语法错误:在按功能传递地图时,在标识符mType之前缺少',' - error C2146: syntax error : missing ',' before identifier mType when passing a map by function C ++错误1错误C2146:语法错误:缺少&#39;;&#39; 在标识符“记录”之前 - C++ Error 1 error C2146: syntax error: missing ';' before identifier 'records' 错误C2146:语法错误:缺少&#39;;&#39; 在标识符&#39;m_ball&#39;C ++之前 - error C2146: syntax error : missing ';' before identifier 'm_ball' C++, MFC VC ++错误C2146:语法错误:标识符&#39;pFirst&#39;之前缺少&#39;)&#39; - VC++ error C2146: syntax error : missing ')' before identifier 'pFirst' 错误C2146:语法错误:缺少&#39;;&#39; 在标识符“ g_App”之前 - error C2146: syntax error : missing ';' before identifier 'g_App' 错误C2146的可能原因:语法错误:缺少';'在标识符之前 - Possible reason for error C2146: syntax error : missing ';' before identifier
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM