I wanted to translate an object following a mouse and these are my coding related to the mouse motion,
void mouseDrag(int x, int y)
if ((state == GLUT_DOWN) && (button == GLUT_LEFT_BUTTON)) // translate
translateX += (400-x)/ 1000.0f;
translateY += (400-y) / 1000.0f;
in gl_draw() i use glTranslatef(translateX,translateY, -6.0f); to translate the object.
and in main()
But I keep getting this error : Error 2 error C2664: ‘glutMotionFunc’ : cannot convert parameter 1 from ‘overloaded-function’ to ‘void (__cdecl *)(int,int)’ F:\UTM courses\OpenGL Tutorials\VidTut\cube\main.cpp 475
I think it refers to the mouseDrag() function. But where is the error?
Thank you very much!!!
The “overloaded funtion” sound like a C++ problem ? Ie. if your function was declared as a pure C function, it would work.
Sorry not good enough at C++ to help more.
It’s more likely that the function is, you know, overloaded. C++ can’t tell which function you mean when you try to pass it as a parameter.
I honestly can’t remember how to get the function pointer for an overloaded function, but the easiest remedy is to simply change the name of the other overloads so that it is no longer overloaded.
mouseDrag is the only function name in my whole program,
to my understanding overloaded function is the function with same name but different parameters, but right now the functions names are all unique.
How can it be overloaded?
Searching the web with your kind of error message, it seems people resolved it by explicitely casting the function pointer to desired type, with static_cast.