gpt4 book ai didi

c++ - 过剩错误消息中的特殊功能

转载 作者:行者123 更新时间:2023-11-28 03:07:40 25 4
gpt4 key购买 nike

不确定如何修复此错误?

这是消息...

 error C2664: 'glutSpecialFunc' : cannot convert parameter 1 from 'void (__cdecl *)(unsigned char,int,int)' to 'void (__cdecl *)(int,int,int)'   
1> None of the functions with this name in scope match the target type

这是我的代码....

函数在主函数中调用。

    glutSpecialFunc(Keyboard); 

这是方法。

void Keyboard(unsigned char key, int x, int y) {

if (key == 27) {
exit(0);
} else if (key == GLUT_KEY_DOWN) {
drawing = 1;
} else if (key == GLUT_KEY_UP) {
drawing = 2;
} else if (key == GLUT_KEY_LEFT) {
drawing = 3;
} else if (key == GLUT_KEY_RIGHT) {
drawing = 4;
}
glutPostRedisplay();
}

最佳答案

glutSpecialFunc(Keyboard); 需要仅包含 int 作为参数的函数。

所以你只需要像这样改变你的函数声明:

  void Keyboard(int key, int x, int y) {

if (key == 27) {
exit(0);
} else if (key == GLUT_KEY_DOWN) {
drawing = 1;
} else if (key == GLUT_KEY_UP) {
drawing = 2;
} else if (key == GLUT_KEY_LEFT) {
drawing = 3;
} else if (key == GLUT_KEY_RIGHT) {
drawing = 4;
}
glutPostRedisplay();
}

来自 openGL 文档:

glutSpecialFunc

glutSpecialFunc sets the special keyboard callback for the current window.

Usage

void glutSpecialFunc(void (*func)(int key, int x, int y));

关于c++ - 过剩错误消息中的特殊功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19309009/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com