I've started making an engine for my games and I have an error which I couldn't fix. Those are the files I have:
Game.h
#pragma once
#include "Core.h"
namespace Honey
{
class HONEY_API Game
{
public:
virtual void OnExecute() { }
virtual void OnClose() { }
};
Game* CreateGamePtr();
#define IMPLEMENT_BASIC_GAME() \
Honey::Game* Honey::CreateGamePtr() \
{\
return new Honey::Game(); \
}
#define IMPLEMENT_GAME(GameClass) \
Honey::Game* Honey::CreateGamePtr() \
{\
return new GameClass(); \
}
}
Engine.h
#pragma once
#include "Core.h"
namespace Honey
{
class Game;
class HONEY_API Engine
{
public:
static bool Init();
void Update() const;
bool Shutdown();
inline static Engine* Get() { return s_Engine; }
inline Game* GetGame() const { return m_Game; }
private:
inline static Engine* s_Engine = nullptr;
Game* m_Game;
};
}
Engine.cpp
#include "Engine.h"
#include "Game/Game.h"
namespace Honey
{
extern Game* CreateGamePtr();
bool Engine::Init()
{
if (Get() || !(s_Engine = new Engine()) || !(s_Engine->m_Game = CreateGamePtr()))
return false;
Get()->GetGame()->OnExecute();
return true;
}
void Engine::Update() const
{
}
bool Engine::Shutdown()
{
if (!Engine::Get() || !GetGame())
return false;
GetGame()->OnClose();
delete this;
return true;
}
}
The project type is DLL. And when try to compile it, it gives me this linking error: LNK2019: unresolved external symbol "class Honey::Game __cdecl Honey::CreateGamePtr(void)" (?CreateGamePtr@Honey@@YAPEAVGame@1@XZ) referenced in function "public: static bool __cdecl Honey::Engine::Init(void)" (?Init@Engine@Honey@@SA_NXZ)*
and, LNK1120: 1 unresolved externals
The CreateGamePtr() is supposed to be declared in the game project so I'm externing it but it doesn't link. I've been trying to fix it for a long time now and nothing has worked so far.