title: Beginner C++: Why is this switch statement giving me an error?
body: <pre><code>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();
  
  }
  </code></pre>
  
  <p>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'?</p>
  
  <p>Thanks!</p>
  
  <p>Edit: The error is: </p>
  
  <pre><code>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;
  </code></pre>