> But, 'static cSingleton instance;' doesn't work well.
I think, it's bug of gcc 3.3
"Doesn't work well" how? Error message? Please post a complete,
compilable program that demonstrates the problem and error messages, if
applicable.
template<class T>
class cSingleton : public T
{
private:
cSingleton() {};
public:
static T* GetInstance()
{
static cSingleton instance;
return &instance;
}
};
Note that the design of this singleton class is actually flawed. The
problem is that the class is templated. This means that your
GetInstance member function has internal linkage and the GetInstance
member function is being duplicated, along with the instance variable,
in each object file in your program. That is, if both a.cpp and b.cpp
use this singleton class, then a.cpp and b.cpp will be accessing
separate instance objects.