GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 17-May-2009, 00:10
AwesDess AwesDess is offline
New Member
 
Join Date: May 2009
Posts: 10
AwesDess is on a distinguished road

A function-definition is not allowed here before '{' token


When I finished the second Lazy Foo SDL tutorial, I had at least 16 errors, I managed to narrow it down to 3 or 4, but I can't fix these guys

I''l give you everything I can give.
My Source Code:
CPP / C++ / C Code:
//The Headers
#include "SDL/SDL.h"
#include <string>

//The Attributes of the screen
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

//The Surfaces That will be used
SDL_Surface*message = NULL;
SDL_Surface*background = NULL;
SDL_Surface*screen = NULL;

SDL_Surface *load_image( std::string filename ) 
{
    //Temporary strogae for the image that is loaded
    SDL_Surface* loadedImage = NULL;
    
    //The optimized image that will be used
    SDL_Surface* optimizedImage = NULL;
    
    //Load the image
    loadedImage = SDL_LoadBMP( filename.c_str() );
    
    //If nothing went wrong in loading the image
    if( loadedImage != NULL )
    {
       //Create an Optimized Image
       optimizedImage = SDL_DisplayFormat( loadedImage ); 
       
       //Free the old image
       SDL_FreeSurface( loadedImage );
       
       //Return the optimized image
       return optimizedImage; 
    }  
    
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination ) 
{
   //Make a temporary rectangle to hold the offsets
   SDL_Rect offset;
   
   //Give the offsets to the rectangle
   offset.x = x;
   offset.y = y;
   
   //Blit the surface
   SDL_BlitSurface( source, NULL, destination, &offset );
}

int main( int argc, char* args[] ) 
{
   //Initialize all SDL Subsystems
   if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
   {
      return 1; 
   }
   
   //Set up the screen
   screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
   
   //If there was an error in setting up the screen
   if( screen == NULL )
   {
       return 1;
   }
   
   //Set the window caption
   SDL_WM_SetCaption( "Hello World", NULL );
   
   //Load the images
   message = load_image("hello_world.bmp");
   background = load_image("background.bmp");
   
   //Apply the background to the screen
   apply_surface( 0, 0, background, screen );
   
   //Apply the message to the screen
   apply_surface( 180, 140, message, screen );
   
   //Update the screen
   if( SDL_Flip( screen ) == -1 )
   {
       return 1;
   }
   
   //Wait 2 seconds
   SDL_Delay( 2000 );
   
   //Free the surfaces
   SDL_FreeSurface( message );
   SDL_FreeSurface( background );
   
   //Quit SDL
   SDL_Quit();
   
   //Return
   return 0;          
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X
Tutorial I followed:
lazyfoo.net/SDL_tutorials/lesson02/index.php
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X
Errors I recieved
Quote:
C:\Dev\Dev-Cpp\SDL Lessons\01\main.cpp In function `SDL_Surface* load_image(std::string)':
---------------------------------------------------------
40 C:\Dev\Dev-Cpp\SDL Lessons\01\main.cpp a function-definition is not allowed here before '{' token
---------------------------------------------------------
53 C:\Dev\Dev-Cpp\SDL Lessons\01\main.cpp a function-definition is not allowed here before '{' token
---------------------------------------------------------
53 C:\Dev\Dev-Cpp\SDL Lessons\01\main.cpp *** [main.o] Error 1
  #2  
Old 17-May-2009, 02:26
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,032
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: Surface Blitting Errors


The closing bracket of your load_image function is positioned after main. Move it where it belongs.
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #3  
Old 17-May-2009, 06:10
AwesDess AwesDess is offline
New Member
 
Join Date: May 2009
Posts: 10
AwesDess is on a distinguished road

Re: Surface Blitting Errors


Quote:
Originally Posted by LuciWiz
The closing bracket of your load_image function is positioned after main. Move it where it belongs.

Thanks. It told me I was missing a closing bracket so I just put it at the end.
  #4  
Old 17-May-2009, 09:56
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Surface Blitting Errors


Ahh, now you see the difference between just doing something and thinking about what you are doing...
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
run script command on ns2.26 newbie06 Computer Software Forum - Linux 65 19-Aug-2009 08:50
Plz anyone help to fix the linking errors: dathatreya MS Visual C++ / MFC Forum 0 03-Apr-2008 01:19
Need urgent help. Nonsensical compile errors on test code (for game) seasons C++ Forum 1 29-Nov-2007 13:41
Compile Errors due to Default Parameters jdbrine C++ Forum 1 17-Jun-2006 15:45

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:35.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.