2014-02-17 69 views
-5

我已經搜遍遍地,無法找到這個相當頻繁發生錯誤的答案。它真的開始煩我了。預期'{'令牌之前的不合格身份證號碼

總之,這是我收到的錯誤:

74:1: error: expected unqualified-id before ‘{’ token 
81:21: error: ‘chat’ has not been declared 
81:5: warning: second argument of ‘int main(int, int**)’ should be ‘char **’ [-Wmain] 
118:10: error: ‘clean_up’ was not declared in this scope 

我還不如干脆張貼整個程序,以避免混淆。可能我注意到我正在學習一個教程,但仍然得到這些錯誤。該教程沒有提供幫助!

#include "SDL/SDL.h" 
#include "SDL/SDL_image.h" 
#include <string> 

const int SCREEN_WIDTH = 640; 
const int SCREEN_HEIGHT = 480; 
const int SCREEN_BBP = 32; 

SDL_Surface* image = NULL; 
SDL_Surface* screen = NULL; 

SDL_Event event; 

SDL_Surface *load_image(std::string filename) 
{ 

SDL_Surface* loadedImage = NULL; 

SDL_Surface* optimizedImage = NULL; 

loadedImage = IMG_Load(filename.c_str()); 

if(loadedImage != NULL) 
    { 

    optimizedImage = SDL_DisplayFormat(loadedImage); 

    SDL_FreeSurface(loadedImage); 
    } 

return optimizedImage; 
} 
void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination) 
{ 
    SDL_Rect offset; 

    offset.x = x; 
    offset.y - y; 

    SDL_BlitSurface(source, NULL, destination, &offset); 
} 
bool init() 
{ 

    if(SDL_Init(SDL_INIT_EVERYTHING) == -1) 
    { 
     return false; 
    } 

    screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BBP, SDL_SWSURFACE); 

    if(screen == NULL) 
    { 
     return false; 
    } 

    SDL_WM_SetCaption("Event test" , NULL); 

    return true; 
} 

bool load_files() 
{ 

    image = load_image("x.png"); 

    if(image == NULL) 
    { 
     return false; 
    } 

    return true; 
} 
{ 

SDL_FreeSurface(image); 

SDL_Quit(); 
} 

int main(int argc, chat* args[]) 
{ 

    bool quit = false; 


    if(init() == false) 
    { 
    return 1; 
    } 

    if(load_files() == false) 
    { 
     return 1; 
    } 

apply_surface(0, 0, image, screen); 

if(SDL_Flip(screen) == -1) 
{ 
    return 1; 
} 

while(quit == false) 
    { 

     while(SDL_PollEvent(&event)) 
     { 

      if(event.type == SDL_QUIT) 
      { 

       quit = true; 
      } 
     } 
    } 

clean_up(); 

return 0; 
} 

任何幫助?

回答

1

要MEE它看起來像你不小心在42行插入一個分號:

bool init(); 
{ //this is line 43 in which the compiler is pointing at. 

試試這樣說:

bool init() 
{ //this is line 43 in which the compiler is pointing at. 
+0

我試過了它出現了一堆其他類似的錯誤 –

+1

你能告訴我們錯誤嗎?也許你在代碼的其他地方有類似的錯誤 – Mikescher

1
bool init(); // <--- you have an extra semicolon here 
{ //this is line 43 in which the compiler is pointing at. 
1

刪除分號bool init();