In C++ I can use typeid
operator to retrieve the name of any polymorphic class:
const char* name = typeid( CMyClass ).name();
The string pointed to by the returned const char*
will be available to my program for as long as the corresponding class exists.
Will multiple calls of typeid(T).name()
return the same pointer value for the same class T
or are they allowed to return different pointers?
No they are not required to return the same pointer.
I have also seen in the wild system that do not.
Each DLL had its own copy of the type object that contained the nmae thus calling the typeid(N).name in shared lib A and shared lib B will result in a different pointer (Though the same underlying string).
Probably, but why rely on that rather than the actual type info if you want to do comparisons?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With