Determine type of child class with baseclass pointer

c++

Solution

Don't.

Use virtual dispatch to achieve different behaviours for different derived types.

Problem

Is there a way to determine the type of a child class with a baseclass pointer? I have declared a pointer in a class constructor like this in .h file ``` baseclass *screen; ``` in constructor ``` screen = new childclass(); ``` Lets say baseclass has 5 different child classes and in my program I switch my pointer around to point towards various child objects, how can I determine the type of the object that screen is currently pointing towards?

Original source