quote:
error C2259: ''Engine'' : cannot instantiate abstract class
Does this mean I''m going to need to make a second template Singleton for an abstract class?
Singleton.h //Common Template
template<typename Type> class Singleton {
public:
inline static Type* Instance() {
if(!pInstance){
pInstance = new Type();
atexit(Cleanup);
}
return pInstance;
}
inline static void Cleanup() {
if(!pInstance) {
delete pInstance;
pInstance = NULL;
}
}
protected:
Singleton(Type* pInst) { pInstance = pInst }
Singleton() { }
Singleton(const Singleton&) { }
virtual ~Singleton() { }
private:
static Type* pInstance;
};
template <typename Type>
Type* Singleton<Type>::pInstance = 0;
System.h //Interface used by alot of classes
class ISystem {
public:
ISystem() :sLabel("System"),sError(":: Exception!") { }
virtual ~ISystem() { }
virtual int Init() = 0;
virtual void Start() = 0;
virtual void Halt() = 0;
virtual void ThrowError() = 0;
protected:
private:
string sLabel;
string sError;
};
Engine.h //Main class, should be both a System and a Singleton
#include "Singleton.h"
#include "System.h"
class Engine : public Singleton<Engine>,public ISystem {
friend class Singleton;
public:
~Engine();
Init();
Start();
Halt();
protected:
Engine();
Engine(const Engine&) { };
Engine& operator= (const Engine&);
private:
};
static Engine *pEngine = Engine::Instance();