Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Template Parameter automatically with Class Name
    primarykey
    data
    text
    <p>I have a triple hierarchy class:</p> <pre><code>template&lt;class T&gt; class Singleton; class Base; class Sub : public Base, public Singleton&lt;Sub&gt;; </code></pre> <p>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:</p> <pre><code>template&lt;class T&gt; class Singleton; class Base : public Singleton&lt;Base&gt;; class Sub : public Base; </code></pre> <p>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).</p> <p>I was wondering if this could be done by pre-processor macros:</p> <pre><code>template&lt;class T&gt; class Singleton; class Base : public Singleton&lt;__CLASS_NAME__&gt;; class Sub : public Base; </code></pre> <p>Where <code>__CLASS_NAME__</code> is the class name that will be replaced by the pre-processor. Theoretically this should be possible, since the <code>__PRETTY_FUNCTION__</code> macro actually returns the class name. The problem is that one cannot do string-manipulation to remove the function name from <code>__PRETTY_FUNCTION__</code>.</p> <p>Any ideas on how I can accomplish this so that the Sub class is not aware of inheriting from a <code>Singleton&lt;template&gt;</code> class?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload