title: Template explicit specialization in class using inheritance
body: <p>Yesterday I asked about template explicit specialization in class.
  <a href="https://stackoverflow.com/questions/69319518/function-with-template-specialization-in-class-without-wrapping-by-class">Link</a>.</p>
  <p>Now I have the same purpose but now I wanna use inheritance to avoid code duplication. If I declare a function in the base class I cannot declare specialization of this function in the derived class.</p>
  <p>My code:</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;stdexcept&gt;
  #include &lt;iostream&gt;
  
  class Base
  {
  public:
      template &lt;typename T&gt;
      T fun()
      {
          throw std::runtime_error(&quot;Unsupported template param&quot;);
      }
  };
  
  class Derived : public Base
  {
  };
  
  template &lt;&gt;
  bool Base::fun&lt;bool&gt;()
  {
      return true;
  }
  
  template &lt;&gt;
  float Derived::fun&lt;float&gt;()
  {
      return 5.6f;
  }
  
  template &lt;&gt;
  double Derived::fun&lt;double&gt;()
  {
      return 5.684;
  }
  
  int main()
  {
      Derived d;
      bool d_b = d.fun&lt;bool&gt;();
      float d_f = d.fun&lt;float&gt;();
      double d_d = d.fun&lt;double&gt;();
      char d_error = d.fun&lt;char&gt;();
  }
  </code></pre>
  <p>VS code errors:</p>
  <blockquote>
  <p>use of inherited members is not allowed</p>
  </blockquote>
  <p>g++</p>
  <blockquote>
  <p>error: template id &quot;fun&quot; for &quot;float Derived :: fun ()&quot; does not match any template declaration</p>
  </blockquote>
  <p>Intel C++ compiler:</p>
  <pre><code>source/app.cpp:25:16: error: no function template matches function template specialization 'fun'
  float Derived::fun&lt;float&gt;()
                 ^
  source/app.cpp:30:1: error: extraneous 'template&lt;&gt;' in declaration of variable 'fun'
  template &lt;&gt;
  ^~~~~~~~~~~
  source/app.cpp:31:17: error: redefinition of 'fun' as different kind of symbol
  double Derived::fun&lt;double&gt;()
                  ^
  source/app.cpp:25:16: note: previous definition is here
  float Derived::fun&lt;float&gt;()
  </code></pre>
  <p>If it is impossible in C++, please answer another question: what is a wide-known practice in c++ to do what I want. Before I used D language and one man says me I don't ask a question &quot;Why&quot; to myself. And instead, I just try to transfer D methods to C++. I agree. That's why I ask.</p>
  <p>Maybe a better way is to ignore templates and declare separated functions? For example:</p>
  <ul>
  <li>funToBool()</li>
  <li>funToFloat()</li>
  <li>funToDouble()</li>
  </ul>