Friday, May 15, 2015

Determine the class of an object at run time

For simplicity, in order to check the class of an derived object is the class I want by a parent object, we can use the code like this:

#include <typeinfo>
if (!strcmp(typeid(*obj).name(), "class MyClass")) printf("It is MyClass!\n");

more details on typeid Reference

No comments:

Post a Comment