Re:Zero-Link error with template singletons
Re:Zero-Link error with template singletons
- Subject: Re:Zero-Link error with template singletons
- From: Nick Kledzik <email@hidden>
- Date: Wed, 3 Dec 2003 17:09:53 -0800
This is an unfortunate out come of the fact that C++ has no concept of
shared libraries. You can reproduce this same problem without
ZeroLink by making a dynamic shared library and application which both
use TimeMgr::GetSingleton(). You will find that at runtime the
application and the library each have their own singleton. (This is
as unsettling as discovering there are parallel universes some of which
contain another you!)
I wrote this up as a bug against ZeroLink. Eventually the C++
standards bodies will work out some standard solution, but in the mean
time ZeroLink should do the right thing.
Nick Kledzik
Developer Tools
Apple Computer, Inc.
If I run without the zero-link option everything is ok, with zero-link
my handle manager classes have problems. Here is my guess about what is
happening. Many of my managers are singletons that are coded using
template <typename T>
class Singleton
{
public:
static T& GetSingleton();
private:
Singleton& operator=( const Singleton& );
};
template< typename T >
T& Singleton<T>::GetSingleton()
{
static T theOne;
return theOne;
}
The manager class then inherent from the singleton like
class TimeMgr : public Singleton< TimeMgr >
using the class as the template argument to create a unique singleton
for the class. Some of the other managers are much more complex
templates, but the idea is the same. The problem seems to be if a use
zero-link I am getting more then one singleton for the same manager
class. Not good. The code is quite large, but I can look at creating
test cases if anyone is interested. For now, I just turned off
zero-link and kept working. Has anyone seen this problem, I didn't see
it in a quick glance through the archive.
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.