I have a code block that I'm trying to convert from PHP to C++ and the compiler is getting hung up on my switch statements.
I have something along the lines of:
switch(//Some int)
{
case 1:
default:
int32 x = 1;
doSomething(x);
break;
case 2:
doSomething(3);
break;
}
And this is throwing errors:
error C2360: initialization of 'x' is skipped by 'case' label
I seem to be able to fix this by declaring and initializing the variables outside of the switch statement, but why is this? What's the problem with creating temporary variables in the scope of a switch statement?
Just for further clarification, I am only attempting to use x
in that one call to doSomething(x)
. I don't attempt to use it outside of the switch statement's scope.