Is dynamic cast appropriate here?

Say in the game, we have Entities that communicate with each other. Let's say that the player collides with an item, and now this item must be placed in hisstd::vector<Item*>

When a player receives a collision message, he receives the item as an object *. Was it then appropriate for the player to apply it as an element, and if the listing succeeds, click the element in inventory?

Even if the game sent him a HIT_ITEM message, he would still need to click it to insert it.

thank

+3
source share
4 answers

dynamic_cast Helps you validate when doing downcasting.

NULL (std::bad_cast ), .

, .

+2

, .

  • *, *?
  • , , ? , ?
  • , , ?

, . , , .

+2

, , - Entity? , , "", - , Item. , dynamic_cast, , - null, .

0

GetType() ? "" .

, RTTI, dynamic_cast (, , ).

-1

All Articles