I was looking through Wesnoth code, and noticed that lately there are
quite a few C-style casts used. E.g.
if(i->second.side() == (size_t)player_number_) {
This is bad practice in C++, since a C-style cast is overpowered -- if
types change around it could end up casting away constness, or
performing an implementation-defined data reinterpretation (basically a
C-style cast is a compiler generated combination of static_cast,
reinterpret_cast, and const_cast).
Good programming style is to use the least powerful tool available that
does what you want. There are two possible correct ways to do this.
Construct a size_t:
if(i->second.side() == size_t(player_number_)) {
Cast to a size_t:
if(i->second.side() == static_cast<size_t>(player_number_)) {
There is no reason that a C-style cast should be used in any situation.
Please don't.
David