3 ms·
I use c style casts everywhere and I've stopped using every other style. Why? Because my projects are my own and I know what everything does and what everythi
by drenvuk 6y ago
I use c style casts everywhere and I've stopped using every other style. Why? Because my projects are my own and I know what everything does and what everything should be. I used the other style in a couple c++ based projects and then never again. Wouldn't touch them unless a team made me.
- stinos 6y agoI know what everything does and what everything should be I used to be like that, but turns out after 5 years not looking at a piece of code you don't know anything anymore (well at least I don't) and then change something only to have something else blow up because, hey, C-style casts ftw right, less typing and less caring. The other casts at least offer some protection against that at compile-time. There's already enough loopholes in C++ that I'd rather have the least worries possible so now I just do the right thing and use the right cast. Heck I might even add a bunch of static_asserts for casts of which I know they'll only be ok if both types are the same size and layout for instance. Plus at the same time they serve as documentation of what I meant when writing he cast. Saved me a bunch of times already.
- Koshkin 6y agoWell, a C-style cast of a pointer to an instance of the derived class to the pointer to the base may not work in case of multiple inheritance, because it is equivalent to reinterpret_cast which effectively does nothing, whereas static_cast will do the right thing.