C++ Qualification conversions - constness and templates
<p>In the code below, I'm trying to figure out why the compiler (msdev c++ 2010 and Comeau) does not consider the return type of the non specialized template get function to be const. I would expect CASE #2 (see code snipet) to NOT compile, yet it does. Any ideas or links?</p>

<p>Thank you, regu</p>

<pre><code>template &lt; typename T &gt;
struct constness
{
  T value;
  constness() : value(0) {}
  const T &amp;get() { return value; }
};

template &lt; typename T &gt;
struct constness&lt; T * &gt;
{
   T * const value;
   constness() : value(0) {}
   const T * const &amp;get() { return value; }
};

int main( int argc, const char* argv[] )
{
  // Uses specialized
  constness&lt; double * &gt; wConstness;
  const_cast&lt; double * &amp; &gt;(wConstness.value) = new double(1);
  *wConstness.get() = 12.0; // CASE #1 doesn't compile

  // Uses non specialized 
  constness&lt; double * const &gt; wConstness2;
  const_cast&lt; double * &amp; &gt;(wConstness2.value) = new double(1);
  *wConstness2.get() = 12.0; // CASE #2 compiles, allowing modification of 
                             // value pointed by wConstness2.value

  return 0;
};
</code></pre>
