|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2005-08-15 16:54:39
"Thorsten Ottosen" <nesotto_at_[hidden]> writes:
>> > > perhaps something like this is needed?
>> >
>> > > template< class Char >
>> > > inline Char* str_end( Char* s )
>> > > {
>> > > - return (Char*)str_end( s, s );
>> > > + return const_cast<Char*>(str_end( s, s ));
>> >
>> > what's the difference? A c-style cast is also a const-cast.
>>
>> You didn't just say that.
>
> Apparently I did.
I must admit I was surprised, too.
> What's the difference in the generated object code?
Thorsten, the difference is in fragility over time with maintenance.
That's why the compiler issues the warning. Any decent beginner's
book on C++ will advise you to eschew all casts, and prefer the
new-style ones. Do you really need to have the fundamentals of good
C++ programming practice explained?
Incidentally, if you find that the proper C++ construct is "less
portable. somehow." you should use BOOST_WORKAROUND to isolate the
compiler for which it fails to work, if only so that the reason for
the workaround is documented.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net