错误为'GLHandler::handleKeys': non-standard syntax; use '&' to create a pointer to member
四次,在不同的功能上。
我正在尝试创建一个包装类来初始化过剩,以使事情更清洁。
出于相同的原因,错误全部显示在4行上,尽管我不确定为什么。
所有这些都设置了回调
内部initGlut函数:
glutKeyboardFunc(this->handleKeys);
glutDisplayFunc(this->render);
glutTimerFunc(1000 / SCREEN_FPS, this->runMainLoop, 0);
内部runMainLoop
函数
glutTimerFunc(1000 / this->SCREEN_FPS, this->runMainLoop, val);
从main内部相同地调用时,抛出在这里的错误不存在,这使我相信该类有问题,但我看不到。
答案 0 :(得分:2)
this->handleKeys
,this->render
和this->runMainLoop
是类方法而不是函数。回调必须是函数或静态方法。
例如请参见glutDisplayFunc
(另请参见freeglut Application Programming Interface):
glutDisplayFunc
设置当前窗口的显示回调。用法
void glutDisplayFunc(void (*func)(void));
注意,类的方法只能由该类的对象调用。指向method
的指针是不够的。您可以将类的方法想象为一个函数,其中第一个参数是指向类对象的指针。
如果有课程
class Foo
{
public:
void render(void);
};
然后可以通过render
获得指向方法&Foo::render
的指针。但是指针的类型是void(Foo::*)(void)
而不是void(*)(void)