YourFace
<span style="color:#9C9C9C;"><strong>Runner Up - T
- Reaction score
- 91
I'm currently using MSVC++ 2008 edition and i have a whole bunch of cpp and header files so i decided to make one for my global variables.
Unfortunately, I keep getting a "redefinition error" even though I only declared the variables once.
here is the header file
here is the cpp file
and this is the main file
I didn't finish the main file since I feel like i need to work more on other parts before i can make runable code. But I tested it to see if there are any simple errors i should fix before they become massive. However I can't fix the redefinition and see the declaration errors
Any tips =)
Unfortunately, I keep getting a "redefinition error" even though I only declared the variables once.
here is the header file
Code:
#ifndef GLOBALVAR_H
#define GLOBALVar_H
#include "SDL.h"
extern const int SCREEN_WIDTH = 960;
extern const int SCREEN_HEIGHT = 960;
extern const int SCREEN_BPP = 32;
extern const int FRAMES_PER_SECOND = 30;
//tiles attribute
extern const int TILE_WIDTH = 64;
extern const int TILE_HEIGHT = 64;
extern const int TOTAL_TILES = 150;
extern const int TOTAL_SPRITES = 64;
//tile sprites
extern SDL_Rect clip[144];
//Images / backgrounds
extern SDL_Surface* screen;
extern SDL_Surface* background;
extern SDL_Surface* Ike;
extern SDL_Surface* thetiles;
#endif
here is the cpp file
Code:
#include "GlobalVar.h"
const int SCREEN_WIDTH = 960;
const int SCREEN_HEIGHT = 960;
const int SCREEN_BPP = 32;
const int FRAMES_PER_SECOND = 30;
//tiles attribute
const int TILE_WIDTH = 64;
const int TILE_HEIGHT = 64;
const int TOTAL_TILES = 150;
const int TOTAL_SPRITES = 64;
//tile sprites
SDL_Rect clip[144];
//Images / backgrounds
SDL_Surface* screen;
SDL_Surface* background;
SDL_Surface* Ike;
SDL_Surface* thetiles;
and this is the main file
Code:
#include "SDL.h"
#include "SDL_image.h"
#include <string>
#include <fstream>
#include "GlobalVar.h"
#include "Tiles.h"
#include "Timer.h"
#include "Unit.h"
SDL_Surface* load_image(std::string filename)
{
SDL_Surface* loadedImage;
SDL_Surface* optimizedImage;
loadedImage = IMG_Load(filename.c_str());
if(loadedImage != NULL)
{
optimizedImage = SDL_DisplayFormat(loadedImage);
if(optimizedImage != NULL)
{
SDL_SetColorKey(optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB(optimizedImage->format, 0xFF, 0xFF,0xFF));
}
return optimizedImage;
}
}
void applysurface(int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect *clip = NULL)
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface(source, clip, destination, &offset);
}
bool init()
{
if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
return false;
}
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);
if(screen == NULL)
{
return false;
}
SDL_WM_SetCaption("Fire Emblem",NULL);
return true;
}
bool load_files()
{
thetiles = load_image("Tiles.png");
if(thetiles == NULL)
{
return false;
}
return true;
}
bool set_tiles(Tiles *tiles[])
{
int x = 0;
int y = 0;
std::ifstream map("Tile.map");
int TileType = -1;
if(map == NULL)
{
return false;
}
for(int i = 0; i <TOTAL_TILES; i++)
{
map>>TileType;
if(map.fail()== true)
{
map.close();
return false;
}
if((TileType >-1) &&(TileType <64))
{
tiles[i] = new Tiles(int x, int y, TileType);
x+=TILE_WIDTH;
if(x > SCREEN_WIDTH)
{
x = 0;
y+= TILE_HEIGHT;
}
}
}
map.close();
return true;
}
int main(int argc, char* args[])
{
bool quit = false;
if(init() == false)
{
return false;
}
if(load_files() == false)
{
return false;
}
Timer fps;
while(quit == false)
{
I didn't finish the main file since I feel like i need to work more on other parts before i can make runable code. But I tested it to see if there are any simple errors i should fix before they become massive. However I can't fix the redefinition and see the declaration errors
:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(5) : error C2374: 'SCREEN_WIDTH' : redefinition; multiple initialization
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(5) : see declaration of 'SCREEN_WIDTH'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(6) : error C2374: 'SCREEN_HEIGHT' : redefinition; multiple initialization
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(6) : see declaration of 'SCREEN_HEIGHT'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(7) : error C2374: 'SCREEN_BPP' : redefinition; multiple initialization
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(7) : see declaration of 'SCREEN_BPP'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(9) : error C2374: 'FRAMES_PER_SECOND' : redefinition; multiple initialization
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(9) : see declaration of 'FRAMES_PER_SECOND'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(11) : error C2374: 'TILE_WIDTH' : redefinition; multiple initialization
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(11) : see declaration of 'TILE_WIDTH'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(12) : error C2374: 'TILE_HEIGHT' : redefinition; multiple initialization
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(12) : see declaration of 'TILE_HEIGHT'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(13) : error C2374: 'TOTAL_TILES' : redefinition; multiple initialization
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(13) : see declaration of 'TOTAL_TILES'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(14) : error C2374: 'TOTAL_SPRITES' : redefinition; multiple initialization
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(14) : see declaration of 'TOTAL_SPRITES'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\fire emblem engine.cpp(97) : error C2062: type 'int' unexpected
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\fire emblem engine.cpp(131) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\garry\desktop\visual studios\fire emblem\fire emblem\fire emblem engine.cpp(130)' was matched
1>Tiles.cpp
1>Unit.cpp
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\unit.cpp(3) : error C2039: 'Movement' : is not a member of 'Unit'
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\unit.h(6) : see declaration of 'Unit'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\unit.cpp(5) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\garry\desktop\visual studios\fire emblem\fire emblem\unit.cpp(4)' was matched
1>GlobalVar.cpp
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.cpp(3) : error C2370: 'SCREEN_WIDTH' : redefinition; different storage class
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(5) : see declaration of 'SCREEN_WIDTH'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.cpp(4) : error C2370: 'SCREEN_HEIGHT' : redefinition; different storage class
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(6) : see declaration of 'SCREEN_HEIGHT'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.cpp(5) : error C2370: 'SCREEN_BPP' : redefinition; different storage class
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(7) : see declaration of 'SCREEN_BPP'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.cpp(7) : error C2370: 'FRAMES_PER_SECOND' : redefinition; different storage class
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(9) : see declaration of 'FRAMES_PER_SECOND'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.cpp(9) : error C2370: 'TILE_WIDTH' : redefinition; different storage class
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(11) : see declaration of 'TILE_WIDTH'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.cpp(10) : error C2370: 'TILE_HEIGHT' : redefinition; different storage class
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(12) : see declaration of 'TILE_HEIGHT'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.cpp(11) : error C2370: 'TOTAL_TILES' : redefinition; different storage class
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(13) : see declaration of 'TOTAL_TILES'
1>c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.cpp(12) : error C2370: 'TOTAL_SPRITES' : redefinition; different storage class
1> c:\users\garry\desktop\visual studios\fire emblem\fire emblem\globalvar.h(14) : see declaration of 'TOTAL_SPRITES'
1>Generating Code...
Any tips =)