Sorry for the title's wording; I don't know how to make it better. But the gist of my question is this:
#include <iostream>
using namespace std;
class Base {};
class Base2 {};
class C : public Base, public Base2 {};
class D : public Base {};
void isDerivedFromBase2(Base *p) {
if (...) { /* test whether the "real object" pointed by p is derived from Base2? */
cout << "true" << endl;
}
cout << "false" << endl;
}
int main() {
Base *pc = new C;
Base *pd = new D;
isDerivedFromBase2(pc); // prints "true"
isDerivedFromBase2(pd); // prints "false"
// ... other stuff
}
How do I test if an object, represented by its base class pointer Base *
, is derived from another base class Base2
?