__cdecl *转换出错

sysmaster 2009-04-07 09:15:05
SDL中的代码代码:
void (SDLCALL *callback)(void *userdata, Uint8 *stream, int len);(在使用SDL时,原来的定义)


自己写的调用代码
class AudioStream
{
.....
SDL_AudioSpec wanted_spec
wanted_spec.callback=audio_callback;(回调函数)
void audio_callback(void *userdata, Uint8 *stream, int len)
{

}
};

编译时的出错信息:


D:\test\ffmpeg\code\LESSION3\first\test.cpp(281) : error C2440: '=' : cannot convert from 'void (__thiscall AudioStream::*)(void *,unsigned char *,int)' to 'void (__cdecl *)(void *,unsigned char *,int)'

如果不用类,那么没有问题。
请问如何解决这个问题?
...全文
269 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
mengde007 2009-04-07
  • 打赏
  • 举报
回复
http://www.yuanma.org/data/2007/0818/article_2816.htm
这儿有详细的介绍。
mengde007 2009-04-07
  • 打赏
  • 举报
回复
看看MSDN有关介绍的
This is the default calling convention for C and C++ programs. Because the stack is cleaned up by the caller, it can do vararg functions. The __cdecl calling convention creates larger executables than __stdcall, because it requires each function call to include stack cleanup code. The following list shows the implementation of this calling convention.
ltc_mouse 2009-04-07
  • 打赏
  • 举报
回复
static
mengde007 2009-04-07
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 mengde007 的回复:]
(__thiscall AudioStream::*)改为_cdecl,标准调用,主要用来清理系统堆栈
[/Quote]这个我说错了,5楼这一贴。
「已注销」 2009-04-07
  • 打赏
  • 举报
回复
如果你实在不想用静态函数,则还可以考虑thunk
可以参考一下:http://www.vckbase.com/document/viewdoc/?id=1818
mengde007 2009-04-07
  • 打赏
  • 举报
回复
void audio_callback(void *userdata, Uint8 *stream, int len) 此方法应该改为静态成员函数,有系统管理
mengde007 2009-04-07
  • 打赏
  • 举报
回复
(__thiscall AudioStream::*)改为_cdecl,标准调用,主要用来清理系统堆栈
「已注销」 2009-04-07
  • 打赏
  • 举报
回复
void audio_callback(void *userdata, Uint8 *stream, int len)要用静态函数,即前面加static
  • 打赏
  • 举报
回复
帮顶吧
mengde007 2009-04-07
  • 打赏
  • 举报
回复
还是标准调用的问题……

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧