Original Post
hmm, to me it seems like I have done an ok Singleton class, but It seems I get an external error when I build the application :/
Singleton.h
[edited by - bilsa on January 5, 2004 2:09:00 PM]
#ifndef SINGLETON
#define SINGLETON
template <class T>;
class Singleton {
public:
static T& GetInstance();
private:
Singleton();
~Singleton();
Singleton(const Singleton&);
Singleton& operator = (const Singleton&);
static T& m_instance;
};
template <class T>
T* Singleton<T>::m_instance = 0;
#endif
Singleton.cpp
#include "Singleton.h"
template <class T>
T& Singleton<T>::GetInstance() {
if (m_instance == 0) {
m_instance = new T;
}
return *m_instance;
}
then I have a class MyClass and try to make it a singleton, like this:
typedef Singleton<MyClass>; MyClass; MyClass& g_MyClass = MyClass::GetInstance();But the "MyClass& g_MyClass = MyClass::GetInstance();" gives me an unresolved external when linking, and I can't figure out what is wrong :/ Would appreicate some help on this