2011-11-24 155 views
0

我試圖用Visual Studio 2010創建一個SDL遊戲,但是當我嘗試構建項目時遇到了很多編譯錯誤。我跟着this tutorial設置了Visual Studio,我正在關注this tutorial for SDL。給我這些錯誤的代碼的兩個部分是我的CApp_OnEvent和CApp文件。Visual Studio 2010 SDL_Event錯誤

CApp_OnEvent:

#include "CApp.h" 

void CApp::OnEvent(SDL_EVENT* Event) { 
} 

CAPP:

#include "CApp.h" 

CApp::CApp() { 
Running = true; 
} 

int CApp::OnExecute() { 
if(OnInit() == false) { 
    return -1; 
} 

SDL_EVENT Event; 

while(Running) { 
    while(SDL_PollEvent(&Event)) { 
     OnEvent(&Event); 
    } 

    OnLoop(); 
    OnRender(); 
} 

OnCleanup(); 

return 0; 
} 

int main(int argc, char* argv[]) { 
CApp theApp; 

return theApp.OnExecute(); 
} 

這裏是Visual Studio中的輸出,當我嘗試建立它:

1>------ Build started: Project: SDL Game, Configuration: Debug Win32 ------ 
1>Build started 11/24/2011 10:58:45 AM. 
1>InitializeBuildStatus: 
1> Touching "Debug\SDL Game.unsuccessfulbuild". 
1>ClCompile: 
1> CApp_OnRender.cpp 
1>c:\users\nathan\documents\visual studio 2010\projects\sdl game\sdl game\capp.h(18): error C2061: syntax error : identifier 'SDL_EVENT' 
1> CApp_OnLoop.cpp 
1>c:\users\nathan\documents\visual studio 2010\projects\sdl game\sdl game\capp.h(18): error C2061: syntax error : identifier 'SDL_EVENT' 
1> CApp_OnInit.cpp 
1>c:\users\nathan\documents\visual studio 2010\projects\sdl game\sdl game\capp.h(18): error C2061: syntax error : identifier 'SDL_EVENT' 
1> CApp_OnEvent.cpp 
1>c:\users\nathan\documents\visual studio 2010\projects\sdl game\sdl game\capp.h(18): error C2061: syntax error : identifier 'SDL_EVENT' 
1>c:\users\nathan\documents\visual studio 2010\projects\sdl game\sdl game\capp_onevent.cpp(3): error C2065: 'SDL_EVENT' : undeclared identifier 
1>c:\users\nathan\documents\visual studio 2010\projects\sdl game\sdl game\capp_onevent.cpp(3): error C2065: 'Event' : undeclared identifier 
1>c:\users\nathan\documents\visual studio 2010\projects\sdl game\sdl game\capp_onevent.cpp(3): error C2448: 'CApp::OnEvent' : function-style initializer appears to be a function definition 
1> CApp_OnCleanup.cpp 
1>c:\users\nathan\documents\visual studio 2010\projects\sdl game\sdl game\capp.h(18): error C2061: syntax error : identifier 'SDL_EVENT' 
1> CApp.cpp 
1>c:\users\nathan\documents\visual studio 2010\projects\sdl game\sdl game\capp.h(18): error C2061: syntax error : identifier 'SDL_EVENT' 
1>c:\users\nathan\documents\visual studio 2010\projects\sdl game\sdl game\capp.cpp(12): error C2065: 'SDL_EVENT' : undeclared identifier 
1>c:\users\nathan\documents\visual studio 2010\projects\sdl game\sdl game\capp.cpp(12): error C2146: syntax error : missing ';' before identifier 'Event' 
1>c:\users\nathan\documents\visual studio 2010\projects\sdl game\sdl game\capp.cpp(12): error C2065: 'Event' : undeclared identifier 
1>c:\users\nathan\documents\visual studio 2010\projects\sdl game\sdl game\capp.cpp(15): error C2065: 'Event' : undeclared identifier 
1>c:\users\nathan\documents\visual studio 2010\projects\sdl game\sdl game\capp.cpp(15): error C3861: 'SDL_PollEvent': identifier not found 
1>c:\users\nathan\documents\visual studio 2010\projects\sdl game\sdl game\capp.cpp(16): error C2065: 'Event' : undeclared identifier 
1> Generating Code... 
1> 
1>Build FAILED. 
1> 
1>Time Elapsed 00:00:00.24 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

您可以查看我的項目的其餘部分代碼去這裏: http://www.mediafire.com/download.php?5524qr1zodracc5

爲什麼我得到這些錯誤的任何想法?謝謝!

+0

可以打開SDL.h在你的項目?可能你忘了在項目屬性中添加額外的包含目錄。 – shadeglare

回答

0

那麼,我已經回答了我自己的問題。我需要使用SDL_Event,而不是SDL_EVENT。

掛在恥辱頭這種低級錯誤