Here is the code.
as you can see, when declare a string test it reports errorsCode:int main(int argc, char* argv[]){ int i=2; switch (i) { case 0: cout<<0<<endl; break; case 1: string test=""; cout<<1<<endl; break; case 2: cout<<2<<endl; break; default: break; } return 0; }
I don't understand the errors, what is "jump to case label" ?main.cc: In function `int main(int, char**)':
main.cc:24: error: jump to case label
main.cc:21: error: crosses initialization of `std::string test'
main.cc:27: error: jump to case label
main.cc:21: error: crosses initialization of `std::string test'
main.cc:24: warning: destructor needed for `std::string test'
main.cc:24: warning: where case label appears here
main.cc:24: warning: (enclose actions of previous case statements requiring
destructors in their own scope.)
main.cc:27: warning: destructor needed for `std::string test'
main.cc:27: warning: where case label appears here
make: *** [main.o] Error 1
why I "crosses initialization of `std::string test'" ?



LinkBack URL
About LinkBacks


