1

I'm using GLUT with C++ and I'm calling a function called glutDisplayFunc with a single argument of the type void (*)(void). For some reason, when I use the following C++ method from one of my classes:

void EventHandler::Render(void) { ... }

It throws this error:

cannot initialize a parameter of type 'void (*)()' with an rvalue of type 'void'

Which seems to give me the thought that my C++ method isn't declared to properly comply with the argument type void (*)(void). What can I do to make my method work with this function parameter?

genpfault
  • 51,148
  • 11
  • 85
  • 139
beakr
  • 5,709
  • 11
  • 42
  • 66

1 Answers1

5

A C++ method is not a normal function. It won't convert to a normal function pointer. You didn't show your actual code, but I'm assuming you did something like:

glutDisplayFunc(EventHandler::Render)

You need to make Render a static method if you want to use it this way. Otherwise declare a free function and use that.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469