int menuDecision = displayMenu();
//WHILE USER DOESN'T SELECT QUIT
while(menuDecision != 3){
/*
if(menuDecision == 1){
Queue myQueue;
}
else{
Stack myStack;
}
*/
switch(menuDecision){
case 1: Queue myQueue;
break;
case 2: Stack myStack;
break;
}
menuDecision = displayMenu();
}
How come when I run the above as a switch statement it's giving me an error but when I use the if/else-if it works? Basically the program instantiates an object depending on what is selected in the menu.Once an object is created the constructor is called, and the constructor calls another function and so on...Basically a new object is created each pass in the while Loop. Since I'm not getting a lot of feedback in my code, would the above implementation be considered 'bad programming'?
Thanks!
Edit: The error is:
main.cpp:27:4: error: cannot jump from switch statement to this case label
case 2: Stack myStack;
^
main.cpp:25:18: note: jump bypasses variable initialization
case 1: Queue myQueue;