I am using forward declaration, and I have already been careful not to have any definition inside header files (only declaration), and also have #pragma once directive before each header file. Yet somehow multiple definition error is still happening. So in GlobalSys.h, I use forward declaration, then i will include this file to any file that needs access to this global variable. In application.h, i initialize this global variable so I have to include EventManager.h or the compiler will complain. Where am I doing wrong?
GlobalSys.h
#pragma once
class EventManager;
namespace GlobalSys {
EventManager * eventManager;
}
Application.h
#include "GlobalSys.h"
#include "../Event/EventManager.h"
class Application {
public:
Application();
};
Application.cpp
#include "Application.h"
Application::Application() {
GlobalSys::eventManager = new EventManager();
}