Jump to Case Label error

This is a discussion on Jump to Case Label error within the C++ Programming forums, part of the General Programming Boards category; I am getting some new error that I don't understand Code: void MainMenu::process_option(int noption)const{ switch (noption){ case 1: display_library(get_ptrLibrary()); break; ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    450

    Jump to Case Label error

    I am getting some new error that I don't understand
    Code:
    void MainMenu::process_option(int noption)const{
        switch (noption){
            case 1:
                    display_library(get_ptrLibrary());
                    break;
            case 2: Menu *ptrEditMenu = new EditMenu(*get_ptrLibrary());
                    while((*ptrEditMenu).get_option()!=6){
                         (*ptrEditMenu).set_option(-1);
                          while (!((*ptrEditMenu).validate_option((*ptrEditMenu).get_option()))){
                                (*ptrEditMenu).display_menu();
                                (*ptrEditMenu).set_option((*ptrEditMenu).input_option());
                         }
                         (*ptrEditMenu).process_option((*ptrEditMenu).get_option());
            
                    }
                    delete ptrEditMenu;
                    
                    break;
            case 3:
            case 4:
            case 5:
            case 6:
            default:
                    break;
        }
    }p
    ainmenu.cpp: In member function `virtual void MainMenu::process_option(int)
    const':
    mainmenu.cpp:61: jump to case label

    mainmenu.cpp:48: crosses initialization of `Menu*ptrEditMenu'
    mainmenu.cpp:62: jump to case label
    mainmenu.cpp:48: crosses initialization of `Menu*ptrEditMenu'
    mainmenu.cpp:63: jump to case label
    mainmenu.cpp:48: crosses initialization of `Menu*ptrEditMenu'
    mainmenu.cpp:64: jump to case label

    mainmenu.cpp:48: crosses initialization of `Menu*ptrEditMenu'
    mainmenu.cpp:65: jump to case label
    mainmenu.cpp:48: crosses initialization of `Menu*ptrEditMenu'

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Put your case statements in brackets, eg:
    Code:
    case 1:
    {
    //...
    
    }
    break;
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    lyx
    lyx is offline
    Amateur
    Join Date
    Sep 2003
    Posts
    228
    Make it clearer! Replace the (*). syntax with the -> one and we'll be able to read more easily.
    The error is explicit, it tells you that a switch or a goto statement can't cross an initialization, so put the Menu * initialization thing out of the structure.

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    Just a noob I kind of like the (*ptr).function notation but I took your suggestion and replaced all that with prt->function is this really easier to read? I guess you don't need the extra parenthasis so here's my changed code just to showoff lol.
    Code:
    Menu *ptrBaseMenu = new MainMenu(library);
      while(ptrBaseMenu->get_option()!=6){
            ptrBaseMenu->set_option(-1);
            while (!(ptrBaseMenu->validate_option(ptrBaseMenu->get_option()))){
                    ptrBaseMenu->display_menu();
                    ptrBaseMenu->set_option(ptrBaseMenu->input_option());
            }
            ptrBaseMenu->process_option(ptrBaseMenu->get_option());
            
      }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  3. How to monitor process creation?
    By markiz in forum Windows Programming
    Replies: 31
    Last Post: 03-17-2008, 02:39 PM
  4. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  5. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21