首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SDL_rect不命名类型

SDL_rect不命名类型
EN

Stack Overflow用户
提问于 2014-07-28 07:58:06
回答 1查看 1.7K关注 0票数 0

我已经试过SDL 2了,正在收到一个SDL_Rect does not name a type错误.守则:

代码语言:javascript
复制
#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;

错误日志:

代码语言:javascript
复制
||=== 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|

我已经在网上查过了另外一个问题,但到目前为止还没能解决这个问题.谢谢各位

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-28 08:11:14

如果我正确地理解了您显示的代码,您将尝试在任何函数之外的全局范围内对矩形进行初始化。这样做是不可能的,你不能在函数之外有赋值语句。

有两种解决办法:

  1. 在声明中初始化,如 SDL_Rect stretchRect ={值..。};
  2. 在全局范围内声明变量,并在函数中初始化: SDL_Rect stretchRect;int (){tenchRect.x=tenchRect.y= 0;tenchRect.w= screenW;tenchRect.h= screenH;.
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24990793

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档