I am trying to write a singleton class for a centralized access point for game data from various classes. Here is what I have... just generic for now.
--> Singleton.h
#pragma once
class Singleton {
public:
static Singleton* instance;
static Singleton* Get();
private:
Singleton() {};
};
Singleton* Singleton::Get() {
instance = new Singleton();
return instance;
}
--> and in the main.cpp I attempt to call into existence the Singleton class
#include "Singleton.h"
Singleton* single = Singleton::Get();
--> and I get the following errors in MS Visual Studio
LNK2001 unresolved external symbol "public: static class Singleton * Singleton::instance" (?instance@Singleton@@2PAV1@A) TimePilot84 E:\VC\TimePilot84\TimePilot84\main.obj 1
I do not understand how to instantiate this class if its constructor is private and if accessing the public constructor is public yet yields an err
I realize that I am not testing to see if the class exists before calling the constructor in the Get function and that I have no destructors as of yet.
I only make one single call to this function in main, and it will not compile. Thanks for your help.