Quote:Original post by BitMaster
Anything you do via static_cast in C++ does not throw away type safety (in general it's just there to avoid a warning).
Nonsense. It throws away type safety.
class Foo{};class Bar : public Foo{ float a;};class Car : public Foo{ int a;};Foo* f = new Bar();Car* c = static_cast<Car*>(f);
Quote:Original post by BitMaster
Anything you do via const_cast does not throw away type safety (provided you can guarantee the data is never written to, so for example a compatibility layer with C code can use it).
removing const is *only* ever needed when you need to write to the variable (otherwise you wouldn't need to get rid of const). const is part of C by the way (just have a look in gl.h, stdlib.h). So by removing the const you are throwing away the type safety (since a programmer will assume that const args passed to a function will not be modified).
Quote:Original post by BitMaster
dynamic_cast does not throw away type safety (and cannot work with a void* pointer to begin with).
True, but I prefer to pretend that one doesn't exist (there are better ways to perform RTTI that don't require tonnes of strcmps). All games will have RTTI disabled...
Quote:The only place where type safety goes out the window is the dreaded reinterpret_cast.
And static cast, and const cast, and the C cast (re-interpret under a different name).