View Full Version : headers
DrKane
2002.05.06, 03:43 PM
I am used to keeping all of my source code in one file. Now that my game is growing larger, I have split my game into many different files. One of my header files which contains all of my global variables, also includes a typedef enum and a Point decleration. The debugger says "illegal name overloading" for every element in the typedef enum. By the way, what are externs and how do you use them?
Mars_999
2002.05.06, 04:03 PM
Originally posted by DrKane
I am used to keeping all of my source code in one file. Now that my game is growing larger, I have split my game into many different files. One of my header files which contains all of my global variables, also includes a typedef enum and a Point decleration. The debugger says "illegal name overloading" for every element in the typedef enum. By the way, what are externs and how do you use them?
extern is a keyword that allows you to use a variable delcared and defined in another file in your project. e.g.
file main.cpp
#include "includes.h"
//global variables
int a = 10;
//main()
int main(int argc, char *argv[])
{
//stuff
return 0;
}
file sprite.cpp is a file to define Sprite Class
//includes.h has sprite.h header
#include "includes.h"
extern int a;
Sprite::Sprite()
{
x = a;
}
Sprite::~Sprite()
{
}
HTH =)
Johan
2002.05.07, 03:32 PM
... One of my header files which contains all of my global variables, also includes a typedef enum and a Point decleration. The debugger says "illegal name overloading" for every element in the typedef enum ...
It seems like you are redefining the typedefs. If you include your header file from multiple files the variables and more importently the typedefs/classes get defined every time. You have to tell the compiler to skip the file if it has already been included.
eg.
(file: globals.h)
#ifndef GLOBALS_H
#define GLOBALS_H
/* Your variables here */
#endif
Cheers,
JP
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.