I have a triple hierarchy class:
template<class T> class Singleton;
class Base;
class Sub : public Base, public Singleton<Sub>;
I' using underlying auto pointers, that's why Singleton is a template class and Sub passes itself as a template parameter. I'm developing Singleton and Base and a public API allows anyone to add their own sub classes. I actually want a real triple hierarchy like this:
template<class T> class Singleton;
class Base : public Singleton<Base>;
class Sub : public Base;
So that external developers don't have to worry about templates and complexity. The problem with this is that my implementation in Singleton will now call the constructor of Base whenever I create an instance of Sub (since the template parameter is Base).
I was wondering if this could be done by pre-processor macros:
template<class T> class Singleton;
class Base : public Singleton<__CLASS_NAME__>;
class Sub : public Base;
Where __CLASS_NAME__
is the class name that will be replaced by the pre-processor. Theoretically this should be possible, since the __PRETTY_FUNCTION__
macro actually returns the class name. The problem is that one cannot do string-manipulation to remove the function name from __PRETTY_FUNCTION__
.
Any ideas on how I can accomplish this so that the Sub class is not aware of inheriting from a Singleton<template>
class?