title: loss of const volatile qualifiers
body: <p>I have a compile error:</p>
  
  <blockquote>
  <pre><code>error C3848: expression having type 'const unicode::endian_swap&lt;T&gt;'
               would lose some const-volatile qualifiers in order to call
               'unsigned long unicode::endian_swap&lt;T&gt;::operator ()(T &amp;)'
  </code></pre>
  </blockquote>
  
  <p>The description of this error, <a href="http://msdn.microsoft.com/en-us/library/t209x37w%28v=vs.80%29.aspx" rel="noreferrer">Here</a>, doesn't really explain what's going on.</p>
  
  <p>I'm unable to reproduce the error in a smaller sample, but I can show the basic layout of my class.</p>
  
  <pre><code>template &lt; typename T &gt;
  struct endian_swap
  {
      endian_swap ( void ) {}
      T operator () ( T&amp; _val ) const { return _val &gt;&gt; 8 | _val &lt;&lt; 8; }
  };
  
  template &lt; typename T &gt;
  struct test
  {
      endian_swap&lt; T &gt; _swap;
  
      virtual void do_it ( ) const
      {
          unsigned short n = 0x1234;
          unsigned short * _dest = &amp;n;
  
          *_dest++ = _swap( n ); // &lt;-- Error is here
      }
  };
  </code></pre>
  
  <p>The error popped up after adding <code>endian_swap</code> as a member. The actual class is derived from <code>std::codecvt</code> and installed into an <code>std::locale</code>.</p>
  
  <p>Can somebody give a better explanation of the error than the site above.</p>
  
  <p>Edit: Actual code:</p>
  
  <pre><code>template &lt; typename T, size_t N = sizeof( T ) &gt; struct endian_swap
  {
      endian_swap ( void ) {};
      T operator () ( const T _val ) const { return _val };
  };
  template &lt; typename T &gt; struct endian_swap&lt; T, 2 &gt;
  {
      endian_swap ( void ) {}
      T operator () ( const T _val ) const { return _val &gt;&gt; 8 | _val &lt;&lt; 8; }
  };
  template &lt; typename T &gt; struct endian_swap&lt; T, 4 &gt;
  {
      endian_swap ( void ) {};
      T operator () ( const T _val ) const { return (_val &gt;&gt; 24) | ((_val &amp; 0x00ff0000) &gt;&gt; 8) | ((_val &amp; 0x0000ff00) &lt;&lt; 8) | (_val &lt;&lt; 24) };
  };
  </code></pre>
  
  <p>Update:
  Found it! Look carefully at the above template and see if you can see it too.</p>