I have my main.cpp file, and I have a slew of headers with class declarations and their accompanying .cpp files with their code. Take, for instance, Dummy1.h and Dummy1.cpp.
Dummy1.h:
Code:
#ifndef DUMMY
class Dummy
{
public:
void DispNum();
int RetInt(int);
float RetFlo(float);
char RetChar(char);
private:
int iDum1;
float fDum2;
char cDum3;
};
#define DUMMY
#endif
Now for Dummy1.cpp:
Code:
#ifndef DUMMY
#include "Dummy1.h"
#endif
char Dummy::RetChar(char arg1)
{
return arg1;
}
void Dummy::DispNum()
{
}
As it is, if I include Dummy1.h in the main.cpp file, everything works. However, if I want to declare something global, I cannot get all appropriate .cpp files to read it. If I try to declare a global variable in the Dummy1.h, I will get this compiler error using Visual Studio 2005:
Shining Exp.obj : error LNK2005: "int giDum1" (?giDum1@@3HA) already defined in Dummy1.obj
C:\Documents and Settings\HP_Administrator\My Documents\Visual Studio 2005\Projects\Shining Exp\Debug\Shining Exp.exe : fatal error LNK1169: one or more multiply defined symbols found
If I declare it in Dummy1.cpp, the Dummy1.h file will not find it. (I am acutally using a considerably more complex header/source combination than this but I used these to simplify things.) If I declare the variable as global in main, I have that same problem. I need a .cpp file to be able to access an array of strings for purposes of object creation (character names), but the.h file needs to "see" that same array for prototypes or else it will be confused. I hope this is not too complex a question, lol. Thanks for any help you have!