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'|
**
你得到什麼錯誤? –
什麼名字?你會*在綁定中遇到綁定一個臨時對象'int&'的問題。我會用'const int&',或者簡單的'int'。 –
@BoPersson有趣的是,我的G ++版本(4.6)用'int&'獲得'throw 0'。 –