title: Getting String Representation of a Template Parameter at Compilation Time
body: <h3>TL;DR</h3>
  <p>How do I initialize a static template variable that will have a different value for each class that inherits from it?</p>
  <h3>Not TL;DR</h3>
  <p>I have the following code in my project, that is intended to identify the class created with a template parameter, to make sure no one else creates it (in a different part of the code, not represented here):</p>
  <pre><code>template &lt;typename T&gt;
  class foo
  {
     ... some other code and methods ...   
     
     virtual const char* getId() 
     {
        return idString;
     }
  
     static const char* const idString;
  };
  </code></pre>
  <p>I would like to initialize idString, so as we know and saw <a href="https://stackoverflow.com/questions/43094045/initialize-a-static-const-member-with-a-template-argument">here</a> and <a href="https://stackoverflow.com/questions/34026555/how-to-define-a-static-const-variable-of-a-template-class">here</a>, I want to initialize the variable in the header file underneath the class definition, where the above class declaration is located:</p>
  <pre><code>template &lt;typename T&gt;
  const char* const idString = strcat(&quot;foo::&quot;, #T);
  </code></pre>
  <p>or something like that, because this does not compile.
  This is done so that the following code:</p>
  <pre><code>class bar : public foo&lt;S&gt;
  {
     ...some other code...
     
     const char* getId()
     {
        return idString;
     }
  
     static const char* const idString;
  };
  </code></pre>
  <p>will generate <code>&quot;foo&lt;S&gt;&quot;</code> when <code>getId()</code> is called with a <code>bar</code> class instance and <code>&quot;foo&lt;T&gt;&quot;</code> when the base class <code>getId()</code> is called, by <strong>hiding</strong> the const variable <code>idString</code> of <code>foo</code> (this is, of course, not an override).</p>
  <p>Thing is, <code>strcat</code> is not a something the compiler can calculate at run time, so this doesn't work well. Currently, the only thing that will work, but has backward compatibility issues is adding a <code>const char*</code> class parameter to the <code>foo</code> class definition, but than each instance of <code>foo&lt;P&gt;</code> will have to beconme <code>foo&lt;P, &quot;foo::P&quot;&gt;</code> manually, and will break previous code uses.</p>
  <p>I have read a few solutions that looked like <a href="https://stackoverflow.com/questions/7545377/getting-a-string-representation-of-a-template-parameter">this</a> which rely on RTTI, but this isn't the case here.</p>
  <p>Thought of using a <code>macro</code> for this, since macros are pre-compilation and can &quot;know&quot; the string representation from the text written, but can't get the syntax properly. Any other suggestions will be incredible! Thank you.</p>