2012-09-02 43 views
0

我想第一次使用异常 但即使它是一个相当简单的示例我只是不能得到它编译,我看过 在几个例子,并试图对其进行编码在 许多,许多不同的方式 但我仍然甚至不能确定究竟在何处 的问题是,因为我有名字修饰 当我介绍捕捉/ TRY /扔反正 这里是我的代码希望它是东西 真的很蠢:)当我尝试使用异常时获取名称mangling [CodeBlocks,C++]

#include "Surface.h" 
#include "SDL_Image.h" 

using namespace std; 

SDL_Surface* surface::Load(string fileName){ 

    SDL_Surface* loadedSurface = IMG_Load(fileName.c_str()); 
    if(loadedSurface == 0) throw 0; 

    //Convert surface to same format as display 
    loadedSurface = SDL_DisplayFormatAlpha(loadedSurface); 

    return loadedSurface; 
} 

#include "GameState.h" 
#include "Surface.h" 

#include<iostream> 

using namespace std; 

GameState::GameState(string fileName){ 

    try{ 
     stateWallpaper_ = surface::Load(fileName); 
    } 
    catch(int& e){ 
     cerr << "Could not load " << fileName << endl; 
    } 
} 

在此先感谢您的帮助!

编辑:对不起,我忘了发布错误信息:这是

In function `ZN14GameStateIntroC1Ev':| 
-undefined reference to `__gxx_personality_sj0'| 
-undefined reference to `_Unwind_SjLj_Register'| 
-undefined reference to `_Unwind_SjLj_Unregister'| 
In function `ZN14GameStateIntroC1Ev':| 
undefined reference to `_Unwind_SjLj_Resume'| 
In function `ZN14GameStateIntroC2Ev':| 
-undefined reference to `__gxx_personality_sj0'| 
-undefined reference to `_Unwind_SjLj_Register'| 
-undefined reference to `_Unwind_SjLj_Unregister'| 
obj\Release\GameStateIntro.o||In function `ZN14GameStateIntroC2Ev':| 
C:\Program Files (x86)\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\ext\new_allocator.h|69|undefined reference to `_Unwind_SjLj_Resume'| 
C:\MinGW\lib\libSDLmain.a(SDL_win32_main.o)||In function `redirect_output':| 
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|219|undefined reference to `SDL_strlcpy'| 
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|220|undefined reference to `SDL_strlcat'| 
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|243|undefined reference to `SDL_strlcpy'| 
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|244|undefined reference to `SDL_strlcat'| 
C:\MinGW\lib\libSDLmain.a(SDL_win32_main.o)||In function `console_main':| 
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|296|undefined reference to `SDL_strlcpy'| 
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|301|undefined reference to `SDL_GetError'| 
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|312|undefined reference to `SDL_SetModuleHandle'| 
C:\MinGW\lib\libSDLmain.a(SDL_win32_main.o)||In function `[email protected]':| 
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|354|undefined reference to `SDL_getenv'| 
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|386|undefined reference to `SDL_strlcpy'| 
C:\MinGW\lib\libSDLmain.a(SDL_win32_main.o)||In function `cleanup':| 
\Users\slouken\release\SDL\SDL-1.2.15\.\src\main\win32\SDL_win32_main.c|158|undefined reference to `SDL_Quit'| 

** 
+3

你得到什么错误? –

+0

什么名字?你会*在绑定中遇到绑定一个临时对象'int&'的问题。我会用'const int&',或者简单的'int'。 –

+0

@BoPersson有趣的是,我的G ++版本(4.6)用'int&'获得'throw 0'。 –

回答

0

从你的错误消息,该问题不涉及任何方式异常,但你的链接。您正在使用SDL标题,但未链接到SDL库,请使用正确的-L选项。

相关问题