i have compile error:
error c3848: expression having type 'const unicode::endian_swap<t>' lose const-volatile qualifiers in order call 'unsigned long unicode::endian_swap<t>::operator ()(t &)'
the description of error, here, doesn't explain what's going on.
i'm unable reproduce error in smaller sample, can show basic layout of 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 here } }; the error popped after adding endian_swap member. actual class derived std::codecvt , installed std::locale.
can give better explanation of error 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) }; }; update: found it! @ above template , see if can see too.
how instantiating template. instantiation of endian_swap uses type t, , pass unsigned short. unless t unsigned short, you'll need conversion, , results of conversion temporary, can't bind non-const reference.
you don't provide sscce, it's hard say. error message post refers call 'unsigned long unicode::endian_swap::operator ()(t &)'; either endian_swapis instantiated forunsigned long(in case, passing anunsigned short` require temporary), or code posted not code triggered error.
Comments
Post a Comment