expected unqualified-id before "using" ??

This is a discussion on expected unqualified-id before "using" ?? within the C++ Programming forums, part of the General Programming Boards category; Ok, I'm completly confused by this error. Here is my main.cpp: Code: #include <stdio.h> #include <stdlib.h> #include <string> #include <windows.h> ...

  1. #1
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309

    expected unqualified-id before "using" ??

    Ok, I'm completly confused by this error.
    Here is my main.cpp:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string>
    #include <windows.h>
    #include <vector>
    #include <iostream>
    #include <SDL/SDL.h>
    #include "map.h"
    using std::vector;
    SDL_Surface *screen = NULL;
    
    vector<SDL_Surface*> images;
    
    void init_imgs(vector<SDL_Surface*> &i)
    {
         SDL_Surface *temp;
         temp = SDL_LoadBMP("img/grass.bmp");
         i.push_back(temp);
         temp = SDL_LoadBMP("img/water.bmp");
         i.push_back(temp);
         SDL_FreeSurface(temp);
    }
    
    int main (int argc, char *argv[])
    {
        char *msg;
        int done;
    
        if (SDL_Init (SDL_INIT_VIDEO) < 0)
        {
            sprintf (msg, "Couldn't initialize SDL: %s\n", SDL_GetError ());
            MessageBox (0, msg, "Error", MB_ICONHAND); 
            free (msg);
            exit (1);
        }
        atexit (SDL_Quit);
    
        /*NOTE: Need a 32x24 array for tiles!*/
        screen = SDL_SetVideoMode (1024, 768, 16, SDL_SWSURFACE | SDL_DOUBLEBUF);
        if (screen == NULL)
        {
            sprintf (msg, "Couldn't set 640x480x16 video mode: %s\n",
              SDL_GetError ());
            MessageBox (0, msg, "Error", MB_ICONHAND); 
            free (msg);
            exit (2);
        }
        SDL_WM_SetCaption ("War of Magic", NULL);
        init_imgs(images);
        Map *abc = new Map("level.txt", images, screen);
        
        done = 0;
        while (!done)
        {
            SDL_Event event;
    
            /* Check for events */
            while (SDL_PollEvent (&event))
            {
                switch (event.type)
                {
                case SDL_KEYDOWN:
                    break;
                case SDL_QUIT:
                    done = 1;
                    break;
                default:
                    break;
                }
            }
        }
    
        return 0;
    }
    Now then, I keep getting the error
    Code:
    expected unqualified-id before "using"
    expected "," or ";" before "using"
    on the line:
    Code:
    using std::vector;
    I've searched google, google groups, and this board but couldn't find anything that seemed relevent to this problem. Can anybody here help?
    To code is divine

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    Assuming map.h is something you've written, look for missing ; close to the end of it.

    > sprintf (msg, "Couldn't initialize SDL: %s\n", SDL_GetError ());
    > free (msg);
    You didn't even malloc your message, so you should be doing neither of these things.
    char msg[1000];
    is far simpler, especially if you use snprintf() as well.

    Though why not use a std::string to store such things?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    Quote Originally Posted by Salem
    Assuming map.h is something you've written, look for missing ; close to the end of it.

    > sprintf (msg, "Couldn't initialize SDL: %s\n", SDL_GetError ());
    > free (msg);
    You didn't even malloc your message, so you should be doing neither of these things.
    char msg[1000];
    is far simpler, especially if you use snprintf() as well.

    Though why not use a std::string to store such things?
    I didn't right that part, it's part of the SDL DevPack.

    Anyways thanks for the suggestion, I'll go look at map.h. Thanks!
    To code is divine

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  2. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 10:23 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  5. Windows using Dev-C++
    By Renegade in forum C++ Programming
    Replies: 15
    Last Post: 07-07-2005, 09:29 PM

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