[英]error: converting from ‘void (FlashWork::*)(int, siginfo_t*, void*)’ to ‘void* (*)(int, siginfo_t*, void*)’
I am a C programmer (on linux), but now I have a project on C++, and have a question. 我是一名C程序员(在Linux上),但是现在我有一个关于C ++的项目,并且有一个问题。
Here is sample code 这是示例代码
g_action.sa_sigaction = (void(*)(int,siginfo_t*,void*))&FlashWork::Disconnect_action;
When I try to compile this on x86, it works fine, but on arm I get the following error 当我尝试在x86上编译它时,它可以正常工作,但是在手臂上,我收到以下错误
error: converting from
void (FlashWork::*)(int, siginfo_t*, void*)
tovoid (*)(int, siginfo_t*, void*)
错误:从void (FlashWork::*)(int, siginfo_t*, void*)
为void (*)(int, siginfo_t*, void*)
What am I doing wrong? 我究竟做错了什么?
"Pointer to members" are not compatible with "pointers to functions", unless it's a static
member. 除非它是static
成员,否则“指向成员的指针”与“指向函数的指针”不兼容。 The reason is that a pointer to member needs an object (a FlashWork
object) in your case. 原因是在您的情况下,指向成员的指针需要一个对象( FlashWork
对象)。
Your function is a member function that returns a void
. 您的函数是一个返回void
的成员函数。 It should be a non-member function (or a static member function) that returns a void *
. 它应该是返回void *
的非成员函数(或静态成员函数)。
Besides the fact the return value of the functions are different, you should know that in C++, when you have a member function ( which is not static ): 除了函数的返回值不同外,您还应该知道在C ++中,当您具有成员函数( 不是静态的 )时:
void (FlashWork::*)(int, siginfo_t*, void*)
The real signature (the one a C programmer likes to see) is this: 真正的签名(C程序员喜欢看到的签名)是:
void (*)(FlashWork *, int, siginfo_t *, void *)
That FlashWork *
parameter is a hidden pointer which can be referred to by this
. 该FlashWork *
参数是一个隐藏的指针,可以由this
引用。
Therefore, 因此,
void (FlashWork::*)(int, siginfo_t*, void*)
and 和
void (*)(int, siginfo_t*, void*)
have different number of arguments. 有不同数量的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.