I have a set of polymorphic C++ classes and they are all instantiated by the same module (Windows DLL). Now having two pointers to such classes and having called typeid
:
SomeCommonBase* first = ...; //valid pointer
SomeCommonBase* second = ...; //valid pointer
const type_info& firstInfo = typeid( first );
const type_info& secondInfo = typeid( second );
can I compare retrieved type_info
addresses
if( &firstInfo == &secondInfo ) {
//objects are of the same class
} else {
//objects are of different classes
}
or use ==
if( firstInfo == secondInfo ) {
//objects are of the same class
} else {
//objects are of different classes
}
to detect whether objects are of (exactly) the same class or of different classes? Is it guaranteed to work when objects are instantiated from within the same module?