1
0

Prefer static_cast to reinterpret_cast (#4223)

* Change reinterpret_cast -> static_cast wherever possible
* Remove more unnecessary `const_cast`s.

reinterpret_casts should be avoided for the same reason as c-style casts - they don't do any type-checking. reinterpret_cast was mainly being used for down-casting in inheritance hierarchies but static_cast works just as well while also making sure that there is actually an inheritance relationship there.
This commit is contained in:
peterbell10
2018-05-02 08:50:36 +01:00
committed by GitHub
parent 86a8fdf3fe
commit a4dbb5c582
48 changed files with 351 additions and 351 deletions

View File

@@ -539,7 +539,7 @@ void cChunk::CollectMobCensus(cMobCensus & toFill)
// LOGD("Counting entity #%i (%s)", (*itr)->GetUniqueID(), (*itr)->GetClass());
if (entity->IsMob())
{
auto & Monster = reinterpret_cast<cMonster &>(*entity);
auto & Monster = static_cast<cMonster &>(*entity);
currentPosition = Monster.GetPosition();
for (const auto & PlayerPos : PlayerPositions)
{
@@ -1902,11 +1902,11 @@ void cChunk::CollectPickupsByPlayer(cPlayer & a_Player)
MarkDirty();
if (Entity->IsPickup())
{
reinterpret_cast<cPickup *>(Entity.get())->CollectedBy(a_Player);
static_cast<cPickup &>(*Entity).CollectedBy(a_Player);
}
else
{
reinterpret_cast<cProjectileEntity *>(Entity.get())->CollectedBy(a_Player);
static_cast<cProjectileEntity &>(*Entity).CollectedBy(a_Player);
}
}
else if (SqrDist < 5 * 5)