View Full Version : cgSetErrorCallback function and VS2005

01-25-2007, 03:46 PM
I am trying to port a project from Visual Studio 2003 to Visual Studio 2005. It consists of a number of classes containing OpenGL and CG code. Here is an extract of the original (VS2003) code:


__nogc class shScene
int GPU_InitializeCG();
void GPU_cgErrorCallback();

int shScene::GPU_InitializeCG()
cgSetErrorCallback( GPU_cgErrorCallback );
}VS2005 follows the C++ standards more strictly than did VS2003, so I had to modify the function pointers as follows:

int shScene::GPU_InitializeCG()
void (shScene::*fnPtr)(void) = &shScene::GPU_cgErrorCallback;
cgSetErrorCallback( fnPtr );
}Although the function pointer itself works fine, I get an error trying to pass it into cgSetErrorCallback:

"error C2664: 'cgSetErrorCallback' : cannot convert parameter 1 from 'void (__thiscall shScene::* )(void)' to 'CGerrorCallbackFunc'"

I can't figure out how to correct this error. Does anybody have any suggestions?


Bruce Merry
01-25-2007, 11:58 PM
cgSetErrorCallback takes a function pointer and not a pointer to member function. The two absolutely cannot be interchanged (for one thing, a member function expects to receive a "this" pointer).

You should pass a plain old global function, which if necessary can be just a helper function that calls back into the class (I think you might also be able to pass a static member function).

01-26-2007, 05:23 AM
Ah! That makes sense...I will give it a try this afternoon. Thanks for the help.