Alrighty Guys this is the entire code being used:
Code:
/***********************************
//** C++ Common Patterns
** Including the Singleton, Facade
** Visitor, and Observer
***********************************/
#define NULL 0
class Singleton
{
public:
static void Create();
static void Destroy();
static Singleton * GetInstance()
{
return s_pInstance;
}
protected:
static Singleton* s_pInstance;
//Hidden Constructor
Singleton();
};
// Implementation
Singleton* Singleton::s_pInstance = NULL;
void Singleton::Create()
{
if(!s_pInstance)
s_pInstance = new Singleton;
}
void Singleton::Destroy()
{
delete s_pInstance;
s_pInstance = NULL;
}
Singleton::Singleton()
{}
That's for the Singleton, here's the test.
Code:
/**************************
*** Singleton Test
***************************/
#include "Singleton.cpp"
#include <iostrEam>
#include <string>
using std::cout;
using std::cin;
using std::string;
class GameEngine : public Singleton
{
public:
void Display();
private:
};
void GameEngine::Display()
{
cout << "Works Fine";
}
int main()
{
GameEngine::Create();
GameEngine::GetInstance()->Display();
string exit;
cin >> exit;
GameEngine::Destroy();
}
That's everything, I get the error compiling the test.