C++ 在'之前应为不合格id;{';代币

C++ 在'之前应为不合格id;{';代币,c++,C++,我找遍了所有的地方,都找不到这个经常出现的错误的答案。它真的开始让我恼火了 无论如何,这是我得到的错误: 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:

我找遍了所有的地方,都找不到这个经常出现的错误的答案。它真的开始让我恼火了

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

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;
}
#包括“SDL/SDL.h”
#包括“SDL/SDL_image.h”
#包括
屏幕宽度=640;
屏幕上的常数=480;
屏幕内常数_BBP=32;
SDL_表面*图像=空;
SDL_表面*屏幕=空;
SDL_事件;
SDL_表面*加载_图像(标准::字符串文件名)
{
SDL_表面*LoadeImage=NULL;
SDL_曲面*optimizedImage=NULL;
LoadeImage=IMG_Load(filename.c_str());
如果(LoadeImage!=NULL)
{
optimizedImage=SDL_显示格式(LoadeImage);
SDL_自由曲面(加载图像);
}
返回优化年龄;
}
void apply_surface(int x,int y,SDL_surface*源,SDL_surface*目标)
{
垂直偏移量;
偏移量x=x;
偏移量y-y;
SDL_BlitSurface(源、空、目标和偏移);
}
boolinit()
{
if(SDL_Init(SDL_Init_EVERYTHING)=-1)
{
返回false;
}
屏幕=SDL_设置视频模式(屏幕宽度、屏幕高度、屏幕BBP、SDL_表面);
如果(屏幕==NULL)
{
返回false;
}
SDL_WM_SetCaption(“事件测试”,空);
返回true;
}
bool load_文件()
{
图像=加载_图像(“x.png”);
if(image==NULL)
{
返回false;
}
返回true;
}
{
SDL_自由曲面(图像);
SDL_退出();
}
intmain(intargc,chat*args[])
{
bool-quit=false;
if(init()==false)
{
返回1;
}
如果(加载_文件()==false)
{
返回1;
}
应用_表面(0,0,图像,屏幕);
如果(SDL_翻转(屏幕)=-1)
{
返回1;
}
while(quit==false)
{
while(SDL_事件和事件))
{
if(event.type==SDL\u QUIT)
{
退出=真;
}
}
}
清理;
返回0;
}

有什么帮助吗?

bool init();//要知道,您似乎不小心在第42行插入了分号:

bool init(); // <--- you have an extra semicolon here
{ //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()
{ //this is line 43 in which the compiler is pointing at.

删除分号
bool init();

我试过了,它出现了一系列类似的错误。你能告诉我们错误吗?也许你在代码的其他地方也有类似的错误