1
votes

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 pointer to member

What was my fault ?

2

2 Answers

4
votes

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).

2
votes

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.