Is casting code okay?
The casting in the code is a normal event or a reason to think about something wrong with the code?
morde last edited by
Casting, the casting's scattering. For example, if you have a code
static_castit might be suspicious, but it's not safe. However, even with
static_castWe need to make sure that this is not just an irresponsible attempt to shut down the compiler, but a clear and necessary transformation. Typically, these things are needed on the library code, but ideally, it's better to avoid and
If your code shows up
dynamic_castI mean, you're probably using polymorphysics wrong. However, in terms of programme accuracy,
dynamic_castis not a problem. He cannot add anything to make the programme incorrect (i.e., he does not serve as a “closing” compiler). Therefore,
dynamic_castmay serve as a sign of incorrect design(s) but not more.
If you have a code
const_castthe most likely thing is that you have a design error in your code that should be corrected as soon as possible. Otherwise, you yourself know what you're doing and
const_castIt's not case. It is only when there are no other options left. And even in this case, it's worth 100 times to think about and weigh, that's it.
const_castdoes not remove the constant from objects that were born in the first place. He can actually take it off, or maybe not take it off, UB if I'm not.
Finally, if you have a code
reinterpret_castand it's not in the code that works on the cross-paid module and the specialised NE module, so you probably have a problem.
If you have a C-style caste in your code, then first, replace them with a C++ analogue and then remove those that are not necessary.
In general, any operator of apparent change is a potential problem, and it is desirable to minimize its use. Each such use should be meaningful and necessary.