You have two options for dealing with constants that cause problems.
Option 1
Remove extern
from header:
#ifndef GLOBALVAR_H #define GLOBALVAR_H #include "SDL.h" const int SCREEN_WIDTH = 960; const int SCREEN_HEIGHT = 960; const int SCREEN_BPP = 32; const int FRAMES_PER_SECOND = 30; const int TILE_WIDTH = 64; const int TILE_HEIGHT = 64; const int TOTAL_TILES = 150; const int TOTAL_SPRITES = 64; extern SDL_Rect clip[144]; extern SDL_Surface* screen; extern SDL_Surface* background; extern SDL_Surface* Ike; extern SDL_Surface* thetiles; extern SDL_Event event; #endif
If you do this, you should not define variables in GlobalVar.cpp
.
Option 2
Remove the initializers from the header:
#ifndef GLOBALVAR_H #define GLOBALVAR_H #include "SDL.h" extern const int SCREEN_WIDTH;
Now you need to define and initialize the constants in GlobalVar.cpp
.
This drawback is that you cannot use names such as SCREEN_WIDTH in contexts that require an integer constant, such as the size of an array or the case
clause of a switch
.
So option 1 is the method that is used more often.
source share