Check for derived type (C++)

前端 未结 6 641
暗喜
暗喜 2020-12-09 12:18

How do I check at runtime if an object is of type ClassA or of derived type ClassB? In one case I have to handle both instances separately

ClassA* SomeClass:         


        
6条回答
  •  既然无缘
    2020-12-09 12:57

    Why not have a doSomething() method on ClassB that handles ClassB's extra capabilities? This is the essence of polymorphism.

提交回复
热议问题