How to know what type of object is pointing a base class pointer?

前端 未结 3 1792
再見小時候
再見小時候 2021-01-28 04:07

I have a base class named Cell (other class has a pointer to an object of this class), and 3 derivated classes CellA, CellB and CellC. When a cell is dead, the pointer points to

3条回答
  •  闹比i
    闹比i (楼主)
    2021-01-28 04:40

    Maybe you need a little bit different logic, take a look on states design pattern I think it could help you. Normally the casting is a bad thing and should be avoided. If you need a casting then you probably have a design issue....

    Good Luck

提交回复
热议问题