Could someone explain to me, how to use a singleton pattern? I tried following this tutorial but I tried to make it on my own and I am getting errors.
main.cpp: undefined refrence to Singleton<Data>::Instance();
main.cpp: undefined refrence to Singleton<Data>::ptr_getSingleton()->PrintData(5);
What would I even Define for these to work?
//Singleton.h
template<class T>
class Singleton
{
private:
static T *m_instance;
protected:
Singleton();
public:
static T *Instance();
static T &ref_getSingleton();
static T *ptr_getSingleton();
};
//Data.h
class Data
{
private:
int iData;
public:
int PrintData(int iData)
{
std::cout << iData << std::endl;
}
};
#include <iostream>
#include "Singleton.h"
#include "Data.h"
int main()
{
Singleton<Data>::Instance();
Singleton<Data>::ptr_getSingleton()->PrintData(5);
return 0;
}