Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;定义函数指针_C++_Function_Pointers - Fatal编程技术网

C++ C++;定义函数指针

C++ C++;定义函数指针,c++,function,pointers,C++,Function,Pointers,我试图在C++中创建一个函数指针到另一个函数。 这就是我到目前为止所做的: LONG (*function)(LPSTR,LPVIPERVAR4,LONG)=&CWilExtender::DllVarHandler; 当我试图编译我的程序时,我得到以下错误: .\MyExtender.cpp(132) : error C2440: 'initializing' : cannot convert from 'LONG (__thiscall CWilExtender::* )(LPSTR

我试图在C++中创建一个函数指针到另一个函数。 这就是我到目前为止所做的:

LONG (*function)(LPSTR,LPVIPERVAR4,LONG)=&CWilExtender::DllVarHandler;
当我试图编译我的程序时,我得到以下错误:

.\MyExtender.cpp(132) : error C2440: 'initializing' : cannot convert from
'LONG (__thiscall CWilExtender::* )(LPSTR,LPVIPERVAR4,LONG)' to
'LONG (__cdecl *)(LPSTR,LPVIPERVAR4,LONG)'
        There is no context in which this conversion is possible
我不知道DllVarHandler是如何定义的,也不知道如何重现函数指针的类型

如何更改
(\u cdecl*)
以匹配
(\u thiscall CWilExtender::*)

具体来说,
LONG(\uu thiscall cFileXtender::*)(LPSTR,LPVIPERVAR4,LONG)
是什么意思?如何将其作为函数指针的类型写入


谢谢。

感谢@OliCharlesworth和@user814628的评论,我解决了我的问题

正确的代码应为:

LONG (CWilExtender::* function)(LPSTR,LPVIPERVAR4,LONG)=&CWilExtender::DllVarHandler;

谢谢你这么快就来帮忙

这个错误消息的可能副本告诉你它期望的是什么类型。在C++中,你可以使用虚拟方法,因此编写既易于阅读又避免了这个问题的代码。使用和接口代替。如果你没有一个好的C++引用,你将很难掌握这一点。即使是经验丰富的程序员,如果不小心,也会犯这种错误。@OliCharlesworth是正确的,您试图表达一个成员函数指针,它不同于函数指针。阅读Oli链接的文章。