11
I have a compile error:
error C3848: expression having type 'const unicode::endian_swap<T>' would lose some const-volatile qualifiers in order to call 'unsigned long unicode::endian_swap<T>::operator ()(T &)'
The description of this error, Here, doesn't really explain what's going on.
I'm unable to reproduce the error in a smaller sample, but I can show the basic layout of my class.
template < typename T >
struct endian_swap
{
endian_swap ( void ) {}
T operator () ( T& _val ) const { return _val >> 8 | _val << 8; }
};
template < typename T >
struct test
{
endian_swap< T > _swap;
virtual void do_it ( ) const
{
unsigned short n = 0x1234;
unsigned short * _dest = &n;
*_dest++ = _swap( n ); // <-- Error is here
}
};
The error popped up after adding endian_swap as a member. The actual class is derived from std::codecvt and installed into an std::locale.
Can somebody give a better explanation of the error than the site above.
Edit: Actual code:
template < typename T, size_t N = sizeof( T ) > struct endian_swap
{
endian_swap ( void ) {};
T operator () ( const T _val ) const { return _val };
};
template < typename T > struct endian_swap< T, 2 >
{
endian_swap ( void ) {}
T operator () ( const T _val ) const { return _val >> 8 | _val << 8; }
};
template < typename T > struct endian_swap< T, 4 >
{
endian_swap ( void ) {};
T operator () ( const T _val ) const { return (_val >> 24) | ((_val & 0x00ff0000) >> 8) | ((_val & 0x0000ff00) << 8) | (_val << 24) };
};
Upda