Hi.
I want to implement a simple singleton class in my UE project, but it gives me errors.
Here is my code for header:
class CRYSTALLIZED_API PathfindingManager
{
private:
PathfindingManager();
PathfindingManager(PathfindingManager const &);
PathfindingManager& operator=(PathfindingManager const&);
protected:
static PathfindingManager *instance;
public:
static PathfindingManager *GetInstance();
static void Destroy();
};
Here is my cpp code:
PathfindingManager *PathfindingManager::GetInstance()
{
if (!instance)
{
instance = new PathfindingManager();
}
return instance;
}
void PathfindingManager::Destroy()
{
delete instance;
}
And these are my errors:
- Error PathfindingManager.cpp.obj : error LNK2019: unresolved external symbol “private: __cdecl PathfindingManager::PathfindingManager(void)” (??0PathfindingManager@@AEAA@XZ) referenced in function “public: static class PathfindingManager * __cdecl PathfindingManager::GetInstance(void)” (?GetInstance@PathfindingManager@@SAPEAV1@XZ)
- Error PathfindingManager.cpp.obj : error LNK2001: unresolved external symbol “protected: static class PathfindingManager * PathfindingManager::instance” (?instance@PathfindingManager@@1PEAV1@EA)
- Error D:_WPI\Term2\Mark\UE4\Crystallized\Binaries\Win64\UE4Editor-Crystallized-2148.dll : fatal error LNK1120: 2 unresolved externals
The problem is in accessing instance. When I remove code from cpp functions everything compiles:
PathfindingManager *PathfindingManager::GetInstance()
{
return NULL;
}
void PathfindingManager::Destroy()
{
}
Please, help me.