Ok. I haven’t posted anything in a (relative) long time. To tell the truth — there isn’t much to report.
Just for the sake of posting something: Here’s my singleton hack from the big bag of stupid-c++-tricks that I wrote for some plugins in melies fx. The following is generally a bad idea for implementing any normal singleton, except in my case where I had to implement one without the client class being aware of its singleton nature. The solution will only work on a class that do not initialize nor assign member variables in the constructor.
- static void* g_pkInstance;
- class MySingleton
- {
- public:
- static void *operator new(std::size_t size)
- {
- if (!g_pkInstance)
- g_pkInstance = ::operator new(size);
- return g_pkInstance;
- }
- MySingleton()
- {
- }
- ~MySingleton()
- {
- }
- };
Post a comment