These are the files in my project:
File.cpp (The main file, doesn't do much... yet)
File.h (Includes some standard libraries and declares the classes. File.h is included in every other file)
Globals.cpp (Declares the member functions, Creates objects out of classes)
???.cpp (All other files...)
These are simplified versions of my files:
FILE.CPP
Code:
#include "File.h"
#include "Globals.cpp"
#include "???.cpp"
#include "???.cpp"
.... (and so on)
int main()
{
//The actual program, not important what it does...
return 0;
}
FILE.H
Code:
#include <conio.h>
#include <stdio.h>
.... (and so on)
class PLAYER;
class ENEMY;
.... (and so on)
GLOBALS.CPP
Code:
#include "File.h"
//Player class
class PLAYER
{
public:
PLAYER();
~PLAYER();
private:
int Hp;
int Mp;
.... (and so on)
};
//Enemy class
class ENEMY
{
public:
ENEMY();
~ENEMY();
private:
int Hp;
int Mp;
.... (and so on)
};
//Creates the objects
PLAYER Player;
ENEMY Enemy;
The problem is that I get the error:
'PLAYER::PLAYER()' is not a member of 'PLAYER'
I tried to put the member declarations in Globals.cpp into File.h like this:
FILE.H
Code:
#include <conio.h>
#include <stdio.h>
.... (and so on)
class PLAYER;
class ENEMY;
.... (and so on)
class PLAYER
{
public:
PLAYER();
~PLAYER();
private:
int Hp;
int Mp;
.... (and so on)
};
class ENEMY
{
public:
ENEMY();
~ENEMY();
private:
int Hp;
int Mp;
.... (and so on)
};
//Creates the objects
PLAYER Player;
ENEMY Enemy;
But then I get the errors:
Multiple declaration for 'PLAYER'
Earlier declaration of 'PLAYER'
The last two errors are obvious since File.h is included several times, which means PLAYER is declared several times...
Help please. What is wrong here?