简体   繁体   English

错误:从'void(FlashWork :: *)(int,siginfo_t *,void *)'转换为'void *(*)(int,siginfo_t *,void *)'

[英]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*) to void (*)(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.

相关问题 sigaction:使用“ void(* sa_sigaction)(int,siginfo_t *,void *);” - sigaction : using “void (*sa_sigaction)(int, siginfo_t *, void *);” siginfo_t尚未声明:由于包含节俭头而引起 - siginfo_t has not been declared: caused by inclusion of a thrift header 从 'void* (*)(int*)' 到 'void* (*)(void*)' 的无效转换 - invalid conversion from 'void* (*)(int*)' to 'void* (*)(void*)' 错误:从&#39;int(*)(void *)&#39;到&#39;void *(*)(void *)&#39;的转换无效 - error: invalid conversion from ‘int (*)(void*)’ to ‘void* (*)(void*)’ 将void *转换为向量<int> - Converting void* to vector<int> 从void *转换为int - Casting from void* to int 错误:无法将&#39;print&#39;从&#39;void(*)(int)&#39;转换为&#39;std :: function <void()> “ - error: could not convert ‘print’ from ‘void (*)(int)’ to ‘std::function<void()>’ 在C ++中从void *转换为int - converting from void* to int in c++ 错误:从类型 &#39;void (*)(int)&#39; {aka &#39;void (*)(int)&#39;} 到类型 &#39;void&#39; 的无效转换 - error: invalid cast from type ‘void (*)(int)’ {aka ‘void (*)(int)’} to type ‘void’ g ++编译器:从&#39;pthread_t {aka long unsigned int}&#39;到&#39;void *(*)(void *)&#39;的错误无效转换[-fpermissive] - g++ compiler: error invalid conversion from 'pthread_t {aka long unsigned int}' to 'void* (*)(void*)' [-fpermissive]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM