Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.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++ 将int传递给CoreTephony obj c中类型为void(*)(void)的参数的不可比较指针类型_C++_C_Core Telephony - Fatal编程技术网

C++ 将int传递给CoreTephony obj c中类型为void(*)(void)的参数的不可比较指针类型

C++ 将int传递给CoreTephony obj c中类型为void(*)(void)的参数的不可比较指针类型,c++,c,core-telephony,C++,C,Core Telephony,CoreTephony.h中定义的函数为 void _CTServerConnectionRegisterForNotification(CTServerConnectionRef,void *,void(*callback)(void)); 然后我尝试调用这个函数 int x = 0; //placehoder for callback _CTServerConnectionRegisterForNotification(conn,kCTCellMonitorUpdateNotificati

CoreTephony.h中定义的函数为

void _CTServerConnectionRegisterForNotification(CTServerConnectionRef,void *,void(*callback)(void));
然后我尝试调用这个函数

int x = 0; //placehoder for callback
_CTServerConnectionRegisterForNotification(conn,kCTCellMonitorUpdateNotification,&x);
它返回错误

将int传递给coretelephony obj c中类型为void(*)(void)的参数的指针类型不兼容


我遗漏了什么?

这里,
\u CTServerConnectionRegisterForNotification()
的第三个参数是指向具有

  • void
    返回类型
  • 不接受任何参数

在这种情况下,您不能传递
int
的地址。它是错误的,并将导致。

CTServerConnectionRegisterForNotification的第三个参数是函数指针,您将指针传递给
int
。即使您成功地使用了强制转换,稍后当连接需要通知您时,它将尝试使用您作为函数传递的值,并且由于它不是函数,您很可能会看到崩溃

使用非整数的函数:

void callback()
{
}
然后在当前代码中:

_CTServerConnectionRegisterForNotification(conn,kCTCellMonitorUpdateNotification,&callback);

感谢您的回复…那么我如何传递int varible?@sai它的名称是
reply
,而不是
replay
:-)为什么首先要传递一个指向
int
的指针呢?:)我刚刚尝试了_CTServerConnectionRegisterForNotification(conn,kCTCellMonitorUpdateNotification,x);但它返回相同的警告这是我的代码void register|u notification(){if(!mach|u port | | |!conn)返回;void*libHandle=dlopen(“/System/Library/Frameworks/corethony.framework/corethony.framework/corethony”,RTLD|LOCAL | RTLD| LAZY);void*kctcellmonitorupdatenofication=dlsym(libHandle,“kctifications”kctiverssign(kCTCellMonitorUpdateNotification==NULL)NSLog(@“找不到kCTCellMonitorUpdateNotification”);int x=0;//回调的placehoder\u ctServerConnectionRegisterNotification(conn,kCTCellMonitorUpdateNotification,&x);}最后一行返回error@sai你没有抓住要点。你为什么要传递一些不是函数指针的东西?你为什么要还原以前的编辑?你在哪里找到那个声明的?这是错误的