Init-declarator?

This is a discussion on Init-declarator? within the C++ Programming forums, part of the General Programming Boards category; I try to compile the following .cpp file, but I get a "expected init-declarator before "enum": Windows XP, code::blocks and ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Init-declarator?

    I try to compile the following .cpp file, but I get a "expected init-declarator before "enum":
    Windows XP, code::blocks and Mingw

    Setup.cpp:

    Code:
    #include "Setup.h"
    #include "includes.h"
    
    enum Subsystem
    {
      video,
      audio,
      timer,
      cd,
      joystick,
      everything,
      evthread
    };
    
    bool Init(int s)
    {
      switch (s)
        {
        case 0:
    
          if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
            {
              return false;
            }
          break;
    
    
    
        case 1:
          if ( SDL_Init( SDL_INIT_AUDIO ) < 0 )
            {
              return false;
            }
          break;
    
    
        case 2:
          if ( SDL_Init( SDL_INIT_TIMER ) < 0 )
            {
              return false;
            }
          break;
    
    
        case 3:
          if ( SDL_Init( SDL_INIT_CDROM ) < 0 )
            {
              return false;
            }
    
          break;
    
    
        case 4:
          if ( SDL_Init( SDL_INIT_JOYSTICK ) < 0 )
            {
              return false;
            }
    
          break;
    
    
        case 5:
          if ( SDL_Init( SDL_INIT_EVERYTHING) < 0 )
            {
              return false;
            }
    
          break;
    
    
        case 6:
          if ( SDL_Init( SDL_INIT_EVENTTHREAD) < 0 )
            {
              return false;
            }
          break;
        default:
          return true;
          break;
    
        }
    }
    what's wrong?

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Check includes.h for a missing semicolon or something.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    17
    Odd, it was an other header file... Why did it show up in that .cpp file. Thanks for help.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    Because when compiling that cpp file it brings in the text in the header files that are included (and the files that those files include and so on). Once all that text is added to the file (figuratively), the compiler then tries to compile the code. The last thing that got included probably had the error and caused the compiler to not understand the enum that was next because it was still waiting for correct syntax to finish the other code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. init adopts zombie process?
    By password636 in forum Linux Programming
    Replies: 4
    Last Post: 07-01-2009, 10:05 AM
  2. Vector doesn't init this way....
    By Yarin in forum C++ Programming
    Replies: 10
    Last Post: 07-10-2008, 02:32 PM
  3. Array of structures in a class, init
    By seizmic in forum C++ Programming
    Replies: 13
    Last Post: 09-17-2005, 01:12 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. How to init an array dynamically on the heap?
    By karantsch in forum C Programming
    Replies: 6
    Last Post: 01-25-2003, 12:07 AM

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