basically this reproduces the problem in a simplified setup. Especially note that we're going through a single instance of the factory, yet still this single instance 'sees' two different locations of the class static variable
48 lines
606 B
C++
48 lines
606 B
C++
|
|
#include "lib/error.hpp"
|
|
|
|
#include "lib/singleton-subclass.hpp"
|
|
|
|
|
|
namespace test {
|
|
|
|
template<typename T>
|
|
struct Holder
|
|
{
|
|
static T* instance;
|
|
|
|
T&
|
|
get()
|
|
{
|
|
if (!instance)
|
|
{
|
|
instance = new T();
|
|
}
|
|
return *instance;
|
|
}
|
|
};
|
|
|
|
|
|
template<typename T>
|
|
T* Holder<T>::instance;
|
|
|
|
struct Subject
|
|
{
|
|
static int cnt;
|
|
|
|
Subject();
|
|
|
|
};
|
|
|
|
typedef lib::SingletonSub<Subject> Factory;
|
|
|
|
extern Factory fab;
|
|
|
|
|
|
|
|
Subject& fabricate();
|
|
|
|
|
|
|
|
|
|
} // namespace test
|