On 21 Sep, 10:21, Juha Nieminen <nos...@thanks.invalidwrote:
jonyman wrote:
I hadn't considered that C casts could remove const ness (I thought
const casting (through const_cast) was a new addition to c++).
C-style casting works as static_cast, reinterpret_cast and const_cast
(hence the general guideline to avoid C-style casts, because they are
confusing and can contain hidden surprises). The only new addition in
C++ is dynamic_cast.
Generally casts are evil. (See the FAQ).
C++ casts are less evil than C casts because you are less likely to
cast away something you didn't intend.
The only time I normally use a C-style cast is if I'm passing a null
pointer (0) to a function that has more than one overload and I want
to tell the compiler what type of pointer I am passing, so
overloaded_func( (const Foo *) 0 );
which is harmless and really there is no need for
overloaded_func( static_cast< const Foo * >( 0 ) );
which is more confusing because it looks like you are converting
something but in reality you are simply clarifying a literal.
I'm not sure if the new standard is going to bring in a typed null
pointer literal. I know that you'll be able to represent a null
pointer unambiguous from integer 0 but not sure it will be totally
typesafe.