This error message appears when a constant is not used in "case" expression. The common mistake is using variables. Ex:
int main()
{
char sw = 'b';
char ch = 'a';
int c;
switch (sw){
case ch: //This line generates C2051
c = 0;
break;
default:
c = 1;
break;
}
}
Use a constant for "case" expression.
int main()
{
char sw = 'b';
int c;
switch (sw){
case 'a':
c = 0;
break;
default:
c = 1;
break;
}
}