Today's programming. The following functions are required in the keyboard response function,
Void keyboard (unsigned char key, int X, int y)
{Switch (key) {Case "S": Case "S": anglex + = 15.0; fig (); break; Case "D": Case "D ": angley + = 15.0; fig (); break;
Case 27: // ESC in the upper left corner of the keyboard
Exit (0); break ;}
}
When compiling in VC, error c2051: Case expression not constant occurs.
I don't think so. Case "S ":
Case "S": it is a constant, character.
I searched the internet for half a day and found a problem with the case expression,
For example, 's' is a constant (single quotes), and "S" is a string (double quotation marks ).
So the solution is to replace the double quotation marks in all case expressions with single quotation marks as follows:
Void keyboard (unsigned char key, int X, int y) {Switch (key) {Case's ': anglex + = 15.0; glupostredisplay (); break; case 'D': angley + = 15.0; fig (); break; Case 27: // ESC in the upper left corner of the keyboard
Exit (0); break;
}
}
Compiled successfully!
I used to solve this problem before, but I couldn't remember it when I used it. I encountered it again today. So I wrote it down for future use!