Casting back to more specialised interface

前端 未结 2 1889
情话喂你
情话喂你 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:41

    Use a type assertion. For example,

    original, ok := entity.(PhysEntity)
    if ok {
        println(original.b())
    }
    

提交回复
热议问题