如何将非静态函数作为回调传递? [英] How do you pass a non-static function as a callback?

查看:66
本文介绍了如何将非静态函数作为回调传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Qt和图形引擎,并且在QGLWidget实例初始化期间,我需要向我的引擎传递一些函数指针.

I'm currently working with Qt and a graphics engine and during the init of the QGLWidget instance I need to pass a few function pointers to my engine.

寻找回调的函数是:

virtual void Buffer::CreateCustom( byte* getsize, byte* makecurrent)

Qt提供了 makeCurrent函数,但是它都不是字节*也不是静态的.

Qt provides a makeCurrent function however it is neither byte* nor static.

我可以这样编写一个小的包装函数:

I could write a tiny wrapper function like so:

void _stdcall MakeCurrent(void)
{
    QGLContext::makeCurrent();
}

但是它仅意味着从GLWidget实例中调用.我试图创建一个像这样的类成员包装函数:

But its only meant to be called from within an instance of GLWidget. I tried to create a class member wrapper function like so:

void _stdcall LEWidget::leMakeCurrent(void)
{
    makeCurrent();
}

但是您只能在静态成员函数上提供函数指针.如果执行此操作,则会出现以下错误:

But you can only provide function pointers on static member functions. If I do that I get the following error:

错误C2352:'QGLWidget :: makeCurrent':非法调用了非静态成员函数.非静态成员引用必须相对于特定对象.

推荐答案

看到这个问题,我认为这几乎是您想要做的事情:

See this question, I think it is pretty much what you want to do:

如何在C ++中实现回调?

这篇关于如何将非静态函数作为回调传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆