I\'m creating a resource manager that takes in classes derived from the class Resource
. My problem is that typeid(..).name() returns the wrong name of the class. >
Firstly, typeid
can provide dynamic run-time type identification only for values of polymorphic class types. Your classes are not polymorphic. You need at least one virtual method in the base class in order to "activate" the dynamic behavior of typeid
.
Secondly, in order to use typeid
for determining the dynamic type of polymorphic object, you have to apply it to the object itself, not to a pointer to the object (as in your code).
Thirdly, the value returned by name()
does not mean much and cannot be used for any practical purposes. Formally, name()
can simply return an empty string every time. You have to use (and compare) the type_info
objects themselves for run-time type identification.