C++回调函数 [英] C++ call back function
本文介绍了C++回调函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在为 CRYPTO_set_locking_callback 传递 C++ 回调函数时出现以下错误.
I get the following error when passing the C++ callback function for the CRYPTO_set_locking_callback.
Error C2664: 'CRYPTO_set_locking_callback' : cannot convert parameter 1 from
'void (__cdecl *)(int,int,char *,int)' to
'void (__cdecl *)(int,int,const char *,int)'
This conversion requires a reinterpret_cast, a C-style cast or
function-style cast
我的代码如下所示:
CRYPTO_set_locking_callback(&MyFunc::lock_callback);
void MyFunc::lock_callback(int mode, int type, char *file, int line)
{
(void)file;
(void)line;
if (mode & CRYPTO_LOCK)
{
pthread_mutex_lock(&(lockarray[type]));
}
else
{
pthread_mutex_unlock(&(lockarray[type]));
}
}
我尝试重新解释演员表,但没有运气,但不确定正确的做法是什么.任何帮助表示赞赏.
I tried reinterpret cast with no luck and not sure what is the correct way of doing it. Any help is appreciated.
推荐答案
根据错误信息,你的函数的第三个参数应该是一个 const char*
:
According to the error message, your function's third argument is supposed to be a const char*
:
void MyFunc::lock_callback(int mode, int type, const char* file, int line)
这应该不是问题,因为您甚至没有使用它.
This shouldn't be a problem, seeing as you're not even using it.
您也可以在文档中看到这一点:
You can see this in the documentation, too:
void CRYPTO_lock(int mode, int n, const char *file, int line);
这篇关于C++回调函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文