我搜遍了整个地方,找不到这个经常重新发生错误的答案。它真的开始惹恼我了。
无论如何,这是我得到的错误:
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;
}
任何帮助?
答案 0 :(得分:1)
bool init(); // <--- you have an extra semicolon here
{ //this is line 43 in which the compiler is pointing at.
答案 1 :(得分: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.
答案 2 :(得分:1)
删除分号bool init();