It was just according to the Singleton pattern there's a static function that returns a instance of the class, which is then called upon.
Instead of mine which is calling static functions of the class.
Yes, that's a choice. You can go both ways.
1) Make all functions + members static
2) Make only the "GetInstance" method static and use the instance it returns to call the non-static member functions. The point is that you can call "GetInstance()" on the class without an instance, thus no need to pass the instance around.
Here's your class definition changed to be a Singleton:
namespace Pro
{
typedef unsigned int GUID;
class GUIDLookup
{
private:
GUIDLookup(); // constructor is private
static GUIDLookup* mInstance; // private instance
public:
static GUIDLookup* GetInstance()
{
if(!mInstance) mInstance = new GUIDLookup();
return mInstance;
}
// all other non-static public methods
// can be called after getting the instance with the method above
GUID newGUID(const std::string& name);
void releaseGUID(const std::string& name);
void releaseGUID(GUID);
GUID getGUIDFromName(const std::string& name);
std::string getName(GUID _id);
};
}
Edit: Oh and you'll have to intialize the mInstance variable to 0/NULL in a static initializer in the implementation file like so (and a better name would probably be msInstance, but it's too early in my timezone :GUIDLookup* GUIDLookup::mInstance = 0;