我有一组多态 C++ 类,它们都由同一个模块(Windows DLL)实例化。现在有两个指向此类类的指针并调用了typeid
:
SomeCommonBase* first = ...; //valid pointer
SomeCommonBase* second = ...; //valid pointer
const type_info& firstInfo = typeid( first );
const type_info& secondInfo = typeid( second );
我可以比较检索到的type_info
地址吗
if( &firstInfo == &secondInfo ) {
//objects are of the same class
} else {
//objects are of different classes
}
或使用==
if( firstInfo == secondInfo ) {
//objects are of the same class
} else {
//objects are of different classes
}
检测对象是(完全)同一类还是不同类?当对象从同一个模块中实例化时,它是否保证工作?