Error+jump+to+case+label+crosses+initialization+of+object

This error occurs with newer version of the gnu compiler. This includes win32 based ides that use gnu as a compiler. Code::Blocks and Eclipse fall under this category. It will, of course, also affect linux based ides.

Here is an example of the error as reported in the Code::Blocks IDE code F:\COURSES\COAP222\PROG\classextra07\circle2.cpp:37: error: jump to case label F:\COURSES\COAP222\PROG\classextra07\circle2.cpp:33: error:  crosses initialization of `Point cent' code

The problem is caused by declaring a variable in a case branch. The compiler cannot resolve the scope. Here is the offending code snippet

code case 2: Point cent = test.get_centre; cout &lt;&lt; "Center is at " &lt;&lt; cent.getx &lt;&lt; ", " &lt;&lt; cent.gety &lt;&lt; endl; break; code

The solution is to simply enclose any case block that declares new variables in curly braces { } so the compiler can resolve the scope of the object.

code case 2: {     Point cent = test.get_centre; cout &lt;&lt; "Center is at " &lt;&lt; cent.getx &lt;&lt; ", " &lt;&lt; cent.gety &lt;&lt; endl; break; } code

There are good discussions of this problem at http://theoryx5.uwinnipeg.ca/gnu/libg++/g++FAQ_42.html