我是SDL的新手,我有一個函數bool init()。我從lazyfoot.net學習SDL 2.0幾天沒有問題。我一直在複製他們的代碼,今天我試圖做我自己的。 (編輯:我知道有人說我有一個過時的頭文件,情況並非如此,因爲自從我安裝該庫以來,我已經可以使用SDL_WINDOWPOS_UNDEFINED和其他2.0功能)。不管出於什麼原因,這都不起作用。(C++)函數不聲明
我使用Windows 7簡易,使用Code :: Blocks的(MinGW的作爲我的編譯器)
當我(嘗試)構建和運行,旁邊還有一個紅色標誌線17,這也是本。
bool init() {
這是整個源代碼。
#include <iostream>
#include <SDL.h>
const int SCREEN_WIDTH = 500;
const int SCREEN_HEIGHT = 500;
bool init();
bool loadMedia();
void quit();
int time = 5000;
SDL_Window* window = NULL;
SDL_Surface* surface = NULL;
SDL_Surface* topImage = NULL;
bool init() {
bool success = true;
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cout << SDL_GetError() << std::endl;
success = false;
}
else{
SDL_CreateWindow("My Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if(window == NULL) {
std::cout << SDL_GetError() << std::endl;
success = false;
}
}
return success;
}
bool loadMedia() {
bool success = true;
surface = SDL_GetWindowSurface(window);
if(surface == NULL) {
std::cout << SDL_GetError() << std::endl;
success = false;
}
else {
topImage = SDL_LoadBMP("image.bmp");
if(topImage = NULL) {
std::cout << SDL_GetError() << std::endl;
success = false;
}
else {
SDL_BlitSurface(topImage, NULL, surface, NULL);
SDL_UpdateWindowSurface(window);
SDL_Delay(time);
}
}
return success;
}
void quit() {
SDL_FreeSurface(topImage);
topImage = NULL;
SDL_DestroyWindow(window);
window = NULL;
surface = NULL;
SDL_Quit();
}
int main(int argc, char* args[]) {
if(init() == true) {
init();
if(loadMedia() == true) {
loadMedia();
}
}
quit();
return 0;
}
嘗試重命名初始化到別的東西。也許這個名字已經在SDL.h中的某個地方使用了 – evpo
這個錯誤實際上說了什麼? –
沒有錯誤。在Code :: Blocks中,第17行旁邊有一個紅色框,顯示有錯誤。我很新的Code :: Blocks,所以也許有一種方法來獲取錯誤,我只是愚蠢的,但我不認爲這種情況 – user3317103