I'm working on a project and I am cleaning my code and Re-doing the code so it's more readable and easy to tweak. I'm having one issue though when I create an object in a header file the complier throws me an error saying its already defined; int assumed. LNK-2005.
I tried creating the objects as 'extern' so I could access the objects from all files that include the file with the specified objects.
// HeaderA.h
#include <Windows.h>
struct ProcessInfo
{
int ProcID;
HANDLE Handle;
};
This is header B below
// Header B starts here
// HeaderB.h
#include "HeaderA.h"
{
ProcessInfo pi;
pi.ProcID = 10;
struct Player
{
int health = 0;
float x, y, z;
int score = 0;
}
}
Header C This file should be able to use Header B's object 'pi'
//HeaderC.h
#include "HeaderB.h"
// creating object from headerB
Player player;
// is there a way so I can use the object declared in HeaderB in HeaderC?
// like so
pi.ProcID = 45;
I expected to be able to use the object created in header B through multiple files like HeaderB-HeaderZ. (A-Z; Multiple Headers) But when compiling I get the error "LNK2005 already defined".