So basically I am trying to create a class and a (static) function to access it, but for some reason the code refuses to compile and throws 2 "unresolved external symbol" errors.
// game.cpp
#include "game.h"
CGame::CGame()
{
// ...
}
CGame* CGame::getInstance()
{
if (s_instance == nullptr)
s_instance = new CGame();
return s_instance;
}
void CGame::run()
{
// ...
}
...
// main.cpp
#include "game.h"
int main()
{
CGame::getInstance()->run();
}
...
#ifndef _GAME_
#define _GAME_
class CGame
{
private:
static CGame* s_instance;
public:
static CGame* getInstance();
void run(); // For testing purposes
CGame();
};
#endif _GAME_
What is the problem here, how can I possibly create a class I [can] use without declaring it?