title: C++ template with 'const'
body: <p>Consider the following template class:</p>
  
  <pre><code>template &lt;typename T&gt; class Function {
  public:
      virtual float eval( const T &amp;x, const T &amp;y ) = 0;
  };
  </code></pre>
  
  <p>Since the 'eval' function should not modify the value of the two inputs 'x' and 'y', I put them as 'const'.
  Then I create the following class derived from Function</p>
  
  <pre><code>class Foo1 : public Function &lt;float*&gt; {
  public:
      Foo1() : Function &lt;float*&gt; () {}
      virtual float eval( const float* &amp;x, const float* &amp;y ) { ... }
  };
  </code></pre>
  
  <p>When I compile with g++, I get the following warning:</p>
  
  <pre><code>hidden overloaded virtual function 'Function&lt;float *&gt;::eval' declared here: type mismatch at 1st parameter
        ('float *const &amp;' vs 'const float *&amp;')
          virtual float eval( const T &amp;x, const T &amp;y ) = 0;
  </code></pre>
  
  <p>And I cannot instantiate the class Foo1. The compiler says that the function 'eval' is not implemented. 
  To make the compiler happy, the derived class must be as follows:</p>
  
  <pre><code>class Foo2 : public Function &lt;float*&gt; {
  public:
      Foo2() : Function &lt;float*&gt; () {}
      virtual float eval( float* const &amp;x, float* const &amp;y ) { ... }
  };
  </code></pre>
  
  <p>Foo2::eval function uses two parameters of type 'float * const' instead of 'const float *'. In other words, Foo2::eval can modify the content of the arrays 'x' and 'y'. This is not what I want. </p>
  
  <p>I have tried to change the template class 'Function' as follows:</p>
  
  <pre><code>    virtual float eval( T const &amp;x, T const &amp;y ) = 0;
  </code></pre>
  
  <p>But the class Foo1 still does not work, the class Foo2 works as in previous case.</p>
  
  <ol>
  <li>So it seems that either 'const T &amp;x' or 'T const &amp;x' in the template class implies 'float* const &amp;x' in the derived class. Is this correct?</li>
  <li>If I want 'const float* &amp;x' (or 'const float* x') in the derived class, what should be my template class Function?</li>
  </ol>
  
  <p>Thank you.</p>