   (__cdecl)  to  (__cdecl*) in C to C++
  Ok this OpenGL code is given in a book as C code, I 've executed it in VS2005 as a C program. When I tried to port it to C++ an error occurs.The OpenGL function declaration is:-void __cdecl Open_GL::drawImage(){int i;glClear(GL_COLOR_BUFFER_BIT);glColor3f(val1,val2,val3);glLoadIdentity();glBegin(GL_POLYGON);// output for triangle verticesfor(i=0;i<3;i++)glVertex3f(*(oldX+i),*(oldY+i),-5.0);glEnd();glFlush();}Error in VS2005:-opengl.cpp(231) : error C2664: 'glutDisplayFunc' : cannot convert parameter 1 from'void (__cdecl Open_GL::* )(void)' to 'void (__cdecl *)(void)'I know those were calling conventions, but i don know how to correct it.....Plz help.......   
  void (__cdecl Open_GL::* )(void)A member function of the Open_GL class, returning void, taking no arguments, and using the __cdecl calling convention.void (__cdecl *)(void)A stand-alone function, returning void, taking no arguments, and using the __cdecl calling convention.The problem is that you're passing the address of a member function, when OpenGL wants a free-standing function. Either make the drawImage() function static, or make it free-standing. But then you'll have to find a way to get an object instance to the function...   ;Quote:Original post by Evil SteveThe problem is that you're passing the address of a member function, when OpenGL wants a free-standing function. Either make the drawImage() function static, or make it free-standing. But then you'll have to find a way to get an object instance to the function...Indeed.  If Open_GL corresponds to a window, I'd suggest using glutGetWindow():class Open_GL {    ...    GLint id;    static std::map< GLint , Open_GL* > instances;public:    Open_GL() {   id = glutCreateWindow( ... );   instances[id] = this;   glutDisplayFunc( display_callback );   ...    }    ~Open_GL() {   instances.erase(id);   ...    }    static void display_callback() {   instances[glutGetWindow()]->drawImage();    }    void drawImage() {   ...    }};std::map< GLint , Open_GL* > Open_GL::instances;;Quote:Original post by MaulingMonkeyQuote:Original post by Evil SteveThe problem is that you're passing the address of a member function, when OpenGL wants a free-standing function. Either make the drawImage() function static, or make it free-standing. But then you'll have to find a way to get an object instance to the function...Indeed.  If Open_GL corresponds to a window, I'd suggest using glutGetWindow():No Open_GL is not a window, its just a class.....here is the main() func:-int main(int argc,char **argv){Open_GL gl;glutInit(&argc,argv);glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );glutInitWindowSize(300,400);glutInitWindowPosition(300,200);glutCreateWindow("My First OpenGL Program");gl.initialize();glutDisplayFunc(&Open_GL::drawImage);glutReshapeFunc(&Open_GL::reshapeWindow);glutMouseFunc(&Open_GL::handleMouse);glutKeyboardFunc(&Open_GL::handleKeyboard);glutMainLoop();return 0;};Quote:Original post by Prasath_AMDQuote:Original post by MaulingMonkeyQuote:Original post by Evil SteveThe problem is that you're passing the address of a member function, when OpenGL wants a free-standing function. Either make the drawImage() function static, or make it free-standing. But then you'll have to find a way to get an object instance to the function...Indeed.  If Open_GL corresponds to a window, I'd suggest using glutGetWindow():No Open_GL is not a window, its just a class.....here is the main() func:-int main(int argc,char **argv){Open_GL gl;glutInit(&argc,argv);glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );glutInitWindowSize(300,400);glutInitWindowPosition(300,200);glutCreateWindow("My First OpenGL Program");gl.initialize();glutDisplayFunc(&Open_GL::drawImage);glutReshapeFunc(&Open_GL::reshapeWindow);glutMouseFunc(&Open_GL::handleMouse);glutKeyboardFunc(&Open_GL::handleKeyboard);glutMainLoop();return 0;}If you have the window managed by your Open_GL class, you can still use the method MaulingMonkey suggested. Otherwise, you'll have to find some other way to get an instance of your Open_GL class from the various callbacks, or use a global variable.A member function is not the same as a standalone function, since it has an implicit "this" pointer. As such, you can't pass a (non-static)member function where a standalone function is expected.   ;  You can't do things that way. Sorry.The conceptual problem is that your functions "belong to" an Open_GL instance - since they are members - and OpenGL has no way of knowing which instance's functions to use.What exactly is an "Open_GL", anyway? What did you hope to gain by creating this class? What does it logically represent?   ;Quote:Original post by ZahlmanYou can't do things that way. Sorry.The conceptual problem is that your functions "belong to" an Open_GL instance - since they are members - and OpenGL has no way of knowing which instance's functions to use.What exactly is an "Open_GL", anyway? What did you hope to gain by creating this class? What does it logically represent?Open_GL is just a class, I created it only to have an OOP approach........Does OpenGLUT functions accept only standalone functions?. That means C++ has no use when programming with OpenGLUT?...........;Quote:Original post by Prasath_AMDOpen_GL is just a class, I created it only to have an OOP approachThat's why I CRY at night. Have you, by any chance, been exposed to radioactive buzzword syndrome or java head-intercourse?;Quote:Original post by Prasath_AMDDoes OpenGLUT functions accept only standalone functions?Yes.Quote:Original post by Prasath_AMDThat means C++ has no use when programming with OpenGLUT?No.   ;Quote:Original post by Prasath_AMDDoes OpenGLUT functions accept only standalone functions?. That means C++ has no use when programming with OpenGLUT?...........It just means that member functions can't be used directly. You'll have to use a proxy function like in MaulingMonkey's solution.   