令牌之前应'{'非限定 ID

expected unqualified id before '{' token

本文关键字:ID 令牌      更新时间:2023-10-16

我已经到处搜索,找不到这个经常发生的错误的答案。它真的开始惹恼我了。

无论如何,这是我遇到的错误:

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;
}

有什么帮助吗?

对我来说,您似乎不小心在第 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.
bool init(); // <--- you have an extra semicolon here
{ //this is line 43 in which the compiler is pointing at.

删除分号bool init();