After I moved some OpenGL code from main function to a new class I had the following error on the following row:
glutDisplayFunc(OnDisplay);
error C3867: 'Room::OnDisplay': function call missing argument list; use '&Room::OnDisplay' to create a po开发者_StackOverflow中文版inter to member
What was my fault ?
glutDisplayFunc
expects a void (*func)(void)
, but you're passing in a void (Room::*func)(void)
.
Since class methods receive an implicit this
parameter, their pointer types are fundamentally different than regular function pointers. There's no conversion possible between them.
All you can do is make OnDisplay
a static member of Room
. From there you can forward the call to a member function of a concrete Room instance (since there is by design only one glut display callback and you migrated from procedural code, I presume you have only a single Room
object somewhere).
glutDisplayFunc
just takes pointer to the function. When moved OnDisplay
to the class, you will also pass the hidden argument this
to glutDisplayFunc
when actually get called.
One possible solution is to make OnDisplay
as a static method.
精彩评论