开发者

Very Quick Globals.h Question (with it included, some of the items still come up undefined)

开发者 https://www.devze.com 2023-03-21 15:26 出处:网络
using globals.h im hoping to store a vector of rectangles and also a collision box and a few global bools

using globals.h im hoping to store a vector of rectangles and also a collision box and a few global bools

globals.h

extern SDL_Rect winRect;

extern std::vector<SDL_Rect> platform;

extern bool paused;
extern bool exit;

i can set the bool to false as so in the globals.cpp.

bool paused = false;
bool exit = false;

ho开发者_高级运维wever then when i try and use the global winRect SDL_Rect or the global vector of SDL_Rects the compiler spits out the "undefined reference to platform" or "to winRect". which i cant understand because they are set up in the globals.h file, and the globals.h is included within the class header that is trying to use them

do i need to define anything else regarding the vector and rect in the globals.cpp file?

might there be something wrong with the order of my header inclusions for the class im trying to manipulate the globals with?

hope there is an easy solution to this, im sure im just missing something.


You need to define winRect and platform in globals.cpp:

SDL_Rect winRect;

std::vector<SDL_Rect> platform;

bool paused = false;
bool exit = false;

Extern only tells the compiler that the variable and/or the function is defined in another place and if you do not define it, the linker will give you an error because it cannot find the definition.


a) Use namespace, probably you have naming collision. b) include header where your SDL_Rect type is defined before defining vector of it

0

精彩评论

暂无评论...
验证码 换一张
取 消