我第一次尝试使用异常,但即使这是一个非常简单的示例,我也无法编译它,我查看了几个示例并尝试以多种不同的方式对其进行编码,但我什至不确定问题到底出在哪里,因为当我引入 catch/try/throw 时,我得到了名称处理,这是我的代码,希望它真的很愚蠢:)
#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 `WinMain@16':|
\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'|
**