C++ Game Programming. Error: expected ')' before ':' token -


i'm going through tutorial on lazyfoo: 'beginning game programming'. i've completed tutorial number 4.

my problem follows:

the code works fine apart line:

sdl_surface* loadsurface( std::string path ); 

the error reads:

error: expected ')' before ':' token

i've come conclusion error might have headers. it's possible should add sdl.h header.

i added stdbool.h header fix separate problem. wonder if has caused issues.

here's full code, tutorial code (edit: i've put problematic line in bold) (or @ least stars have gone around it. doesn't appear bolding within code. it's near beginning, line 33):

//using sdl , standard io #include <sdl.h> #include <stdio.h> #include <stdbool.h> #include <string.h> #include <stdlib.h>  //screen dimension constants const int screen_width = 640; const int screen_height = 480;  //key press surfaces constants enum keypresssurfaces {     key_press_surface_default,     key_press_surface_up,     key_press_surface_down,     key_press_surface_left,     key_press_surface_right,     key_press_surface_total };  //starts sdl , creates window bool init();  //loads media bool loadmedia();  //frees media , shuts down sdl void close();  //loads individual image **sdl_surface* loadsurface( std::string path );**  //the window we'll rendering sdl_window* gwindow = null;  //the surface contained window sdl_surface* gscreensurface = null;  //the images correspond keypress sdl_surface* gkeypresssurfaces[ key_press_surface_total ];  //current displayed image sdl_surface* gcurrentsurface = null;  bool init() {     //initialization flag     bool success = true;      //initialize sdl     if( sdl_init( sdl_init_video ) < 0 )     {         printf( "sdl not initialize! sdl_error: %s\n", sdl_geterror() );         success = false;     }     else     {         //create window         gwindow = sdl_createwindow( "sdl tutorial", sdl_windowpos_undefined, sdl_windowpos_undefined, screen_width, screen_height, sdl_window_shown );         if( gwindow == null )         {             printf( "window not created! sdl_error: %s\n", sdl_geterror() );             success = false;         }         else         {             //get window surface             gscreensurface = sdl_getwindowsurface( gwindow );             }         }          return success; }  bool loadmedia() {     //loading success flag     bool success = true;      //load default surface     gkeypresssurfaces[ key_press_surface_default ] = loadsurface( "04_key_presses/press.bmp" );     if( gkeypresssurfaces[ key_press_surface_default ] == null )     {         printf( "failed load default image!\n" );         success = false;     }      //load surface     gkeypresssurfaces[ key_press_surface_up ] = loadsurface( "04_key_presses/up.bmp" );     if( gkeypresssurfaces[ key_press_surface_up ] == null )     {         printf( "failed load image!\n" );         success = false;     }      //load down surface     gkeypresssurfaces[ key_press_surface_down ] = loadsurface( "04_key_presses/down.bmp" );     if( gkeypresssurfaces[ key_press_surface_down ] == null )     {         printf( "failed load down image!\n" );         success = false;     }      //load left surface     gkeypresssurfaces[ key_press_surface_left ] = loadsurface( "04_key_presses/left.bmp" );     if( gkeypresssurfaces[ key_press_surface_left ] == null )     {         printf( "failed load left image!\n" );         success = false;     }      //load right surface     gkeypresssurfaces[ key_press_surface_right ] = loadsurface( "04_key_presses/right.bmp" );     if( gkeypresssurfaces[ key_press_surface_left ] == null )     {         printf( "failed load left image!\n" );         success = false;     }      return success; }  void close() {     int i;     //deallocate surface     for( < key_press_surface_total; ++i; )     {     sdl_freesurface( gkeypresssurfaces[ ] );     gkeypresssurfaces[ ] = null;     }      //destroy window     sdl_destroywindow( gwindow );     gwindow = null;      //quit sdl subsystems     sdl_quit(); }  sdl_surface* loadsurface( std::string path ) {     //load image @ specified path     sdl_surface* loadedsurface = sdl_loadbmp( path.c_str() );     if( loadedsurface == null )     {         printf( "unable load image %s! sdl error: %s\n", path.c_str(), sdl_geterror() );     }      return loadedsurface; }  int main( int argc, char* args[] ) {      //start sdl , create window     if( !init() )     {         printf( "failed initialize!\n" );     }     else     {         //load media         if( !loadmedia() )         {             printf( "failed load media!\n" );         }         else         {             //main loop flag             bool quit = false;              //event handler             sdl_event e;              //set default current surface             gcurrentsurface = gkeypresssurfaces[ key_press_surface_default ];              //while application running             while( !quit )             {                 //handle events on queue                 while( sdl_pollevent( &e ) != 0 )                 {                     //user requests quit                     if( e.type == sdl_quit )                     {                         quit = true;                     }                     //user presses key                     else if( e.type == sdl_keydown )                     {                         //select surfaces based on key press                         switch( e.key.keysym.sym )                         {                         case sdlk_up:                         gcurrentsurface = gkeypresssurfaces[ key_press_surface_up ];                         break;                          case sdlk_down:                         gcurrentsurface = gkeypresssurfaces[ key_press_surface_down ];                         break;                          case sdlk_left:                         gcurrentsurface = gkeypresssurfaces[ key_press_surface_left ];                         break;                          case sdlk_right:                         gcurrentsurface = gkeypresssurfaces[ key_press_surface_right ];                         break;                          default:                         gcurrentsurface = gkeypresssurfaces[ key_press_surface_default ];                         break;                         }                     }                     }                  //apply current image                 sdl_blitsurface( gcurrentsurface, null, gscreensurface, null );                  //update surface                 sdl_updatewindowsurface( gwindow );                     }                  }     }      //free resources , close sdl     close();      return 0;  } 

as pointer out, should try including c++'s string.

#include <string> 

however, if that's problem, compiler should have said string not in std namespace.


to me looks compiler doesn't know :: namespace operator.

the possible cause you're using c compiler instead of c++ compiler.

c doesn't have notion of namespace, , has no std::string.


make sure source file's extension c++ 1 (like .cpp) opposed c (.c).

depending on compiler, might need tell mean c++ , not c. if you're using gcc, try g++ instead.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -