problems with undefined references
Gokhan Kisacikoglu
kisa@centropolisfx.com
Tue Jun 25 10:04:00 GMT 2002
Here I fixed your source code and attached it. You did not declare the
static variable anywhere, it is also safer to call the static variable
with its scope.
Gokhan
-------------- next part --------------
#include "Singleton.h"
//=========================================================================
// Singleton class implementation
// only the default constructor is implemented as it is the only constructor
// that will be used so we will not get "undefined references" for the copy
// constructor and assignment operator when linking
//
SingletonDestroyer Singleton :: destroyer;
//-------------------------------------------------------------------------
// initialize the pointer to the single isntance
Singleton* Singleton::instance = 0;
//-------------------------------------------------------------------------
// default constructor (just initialises imlp)
Singleton::Singleton()
{
}
//-------------------------------------------------------------------------
// getInstance:
// if NULL construct the sinle instance, otherwise just return it
Singleton* Singleton::getInstance()
{
// is it the first call?
if (instance == 0)
{
// create sole instance
instance = new Singleton;
Singleton :: destroyer.setSingleton(instance);
}
// return the address of sole instance
return instance;
}
Singleton::~Singleton()
{
}
//=========================================================================
// SingletonDestroyer class implementation
SingletonDestroyer::~SingletonDestroyer()
{
delete instance;
}
void SingletonDestroyer::setSingleton( SingletonPtr _instance)
{
instance = _instance;
}
More information about the Gcc-help
mailing list