我的代码:
window.cpp
Window::Window(int w, int h, const char *title, const char *icon) { height = h; width = w; if(SDL_Init( SDL_INIT_EVERYTHING ) == 0) { SDL_WM_SetCaption(title, NULL); SDL_WM_SetIcon(SDL_LoadBMP(icon),NULL); screen = SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE | SDL_RESIZABLE | SDL_DOUBLEBUF); if(screen == NULL) { running = false; return; } fullscreen = false; } else running = false; return; } Window::Window() { const SDL_VideoInfo* info = SDL_GetVideoInfo(); screenWidth = info->current_w; screenHeight = info->current_h; Window(640, 480, "Flatgu game", "rsc/img/icon.bmp"); }
在window.h
class Window { public: Window(); ~Window(); int getWidth() {return width;} int getHeight() {return height;} bool isFullscreen() {return fullscreen;} void toggleFullscreen(); private: Window(int w, int h, const char *title, const char *icon); bool fullscreen, running; int height, width, screenWidth, screenHeight; SDL_Surface *screen; };
它编译罚款,但随后,编译后,我得到这个丑陋的错误:
什么是我的问题的原因是什么? 为什么会如此怪异的数字?
我的目标是存储原始的屏幕分辨率为进一步使用 (如切换到全屏 ),我有打电话之前要做到这一点SDL_SetVideoMode()
这就是为什么它是在构造函数中。