Function call

Started by
2 comments, last by ganecj 12 years, 4 months ago
Good day all,




in Opengl , I have a function:

glutDisplayFunc();

Instead of passing a standalone function into it, would it be possible for me to pass in a class function?




for example

class graphic

{

public

void run();
};





void main ()

{

class graphic temp;

glutDisplayFunc( temp.run);
}




Advertisement
Unfortunately, no.
You can have a global object or pointer, and call methods on it:

graphic *g_graphic = 0;

void runGlobal()
{
assert(g_graphic);
g_graphic->run();
}

int main()
{
graphic graphics;
g_graphic = &graphics;
glutDisplayFunc(&runGlobal);
g_graphic = 0;
}
Thank you, guys for your prompt reply.

This topic is closed to new replies.

Advertisement