Possible to Use typeid to Determine Parent-Child Relationship
c++
Solution
I don't think you can do that in current C++ using the information in `typeinfo` only. I know of `boost::is_base_of` (Type Traits will be part of C++0x):
if ( boost::is_base_of<A, B>::value ) // true
{
std::cout << "A is a base of B";
}
Problem
all the while, I am using dynamic_cast to determine Parent-Child relationship of an object. ``` #include <iostream> class A { public: virtual ~A() {} }; class B : public A { }; class C : public A { }; int main() { B b; std::cout<< typeid(b).name()<< std::endl; // class B A* a = dynamic_cast<A *>(&b); if (a) { std::cout<< "is child of A"<< std::endl; // printed } C* c = dynamic_cast<C *>(&b); if (c) { std::cout<< "is child of C"<< std::endl; // Not printed } getchar(); } ``` May I know is it possible that I can determine parent-child relationship, of an object, through typeid? For example, how I can know B is the child of A, by using typeid checking? Thanks.