Casting back to more specialised interface

前端 未结 2 1887
情话喂你
情话喂你 2021-01-30 05:14

I\'m writing a game in go. In C++ I would store all my entity classes in an array of the BaseEntity class. If an entity needed to move about in the world it would be a PhysEntit

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-30 05:27

    Specifically, the Go "interface" type has the information on what the object really was, that was passed by interface, so casting it is much cheaper than a C++ dynamic_cast or the equivalent java test-and-cast.

提交回复
热议问题