我一直在试用SDL 2,并收到SDL_Rect does not name a type
错误...
代码:
#include <stdio.h>
#include <SDL.h>
using namespace std;
SDL_Window* gWindow = NULL;
SDL_Surface* gWSurface = NULL;
SDL_Surface* gFinalImage = NULL;
int screenW = 640;
int screenH = 480;
SDL_Rect stretchRect;
stretchRect.x = stretchRect.y = 0;
stretchRect.w = screenW;
stretchRect.h = screenH;
错误日志:
||=== Build: Debug in SDLEvents (compiler: GNU GCC Compiler) ===|
D:\My Works\SDL Stretching\TestingSDL.cpp|12|error: 'stretchRect' does not name a type|
D:\My Works\SDL Stretching\TestingSDL.cpp|13|error: 'stretchRect' does not name a type|
D:\My Works\SDL Stretching\TestingSDL.cpp|14|error: 'stretchRect' does not name a type|
我已经在网上和另一个问题进行了检查,但到目前为止尚无法解决问题.... 谢谢你们
答案 0 :(得分:3)
如果我理解你正确显示的代码,你会尝试在任何函数之外的全局范围内初始化矩形。这样做不可能,你不能在函数之外使用赋值语句。
有两种解决方案:
在声明中初始化,如
SDL_Rect stretchRect = { values... };
在全局范围内声明变量,并在函数中初始化:
SDL_Rect stretchRect;
...
int main()
{
stretchRect.x = stretchRect.y = 0;
stretchRect.w = screenW;
stretchRect.h = screenH;
...