Is there any way to get typeid() to return the derived class name?

Hi, I've been looking through the boost library and I haven't been able to find anything that works like typeid() that returns the exact (i.e. derived) class name instead of just the base class. I want to compare two derived classes to make sure that they are of the same class, but typeid() only returns the name of the base class. If there is a boost function that does this, or if someone has a way of doing it could you please point me in the right direction? Thanks, Chris Just __________________________________ Do you Yahoo!? Yahoo! Mail - You care about security. So do we. http://promotions.yahoo.com/new_mail

The serialization system has a class - extended_type_info which does exactly this. You might not like the way it does it - but there it is. Robert Ramey Chris Just wrote:
Hi, I've been looking through the boost library and I haven't been able to find anything that works like typeid() that returns the exact (i.e. derived) class name instead of just the base class.
I want to compare two derived classes to make sure that they are of the same class, but typeid() only returns the name of the base class.
If there is a boost function that does this, or if someone has a way of doing it could you please point me in the right direction?
Thanks, Chris Just
__________________________________ Do you Yahoo!? Yahoo! Mail - You care about security. So do we. http://promotions.yahoo.com/new_mail _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Chris Just <cpjust@yahoo.com> writes:
Hi, I've been looking through the boost library and I haven't been able to find anything that works like typeid() that returns the exact (i.e. derived) class name instead of just the base class.
I know this is going to seem nitpicky, but it affects my ability to know how to help you: typeid doesn't return names; it returns type_info objects.
I want to compare two derived classes to make sure that they are of the same class, but typeid() only returns the name of the base class.
If you have two classes, A and B, you can just use boost::is_same<A,B>::value. But I don't think that's what you mean. I assume you mean that you want to compare the type of two objects x and y to which you hold base class pointers or references? If the objects' classes are polymorphic, template <class A, class B> bool same_derived_class(A const& a, B const& b) { return typeid(a) == typeid(b); }; should work, with no additional help from a Boost library... ...which makes me very confused about what you're trying to achieve. -- Dave Abrahams Boost Consulting www.boost-consulting.com

On Mon, 28 Feb 2005 19:33:40 -0800 (PST) Chris Just <cpjust@yahoo.com> wrote:
Hi, I've been looking through the boost library and I haven't been able to find anything that works like typeid() that returns the exact (i.e. derived) class name instead of just the base class.
I want to compare two derived classes to make sure that they are of the same class, but typeid() only returns the name of the base class.
If there is a boost function that does this, or if someone has a way of doing it could you please point me in the right direction?
Funny about timing... I think I can answer your question, but I must answer with another question. What do you mean by "typeid() only returns the name of the base class?" This is surely not the case for polymorphic types, at least according to the standard. Maybe if you post a bit of code, which represents what you are trying to accomplish, I can help...
participants (4)
-
Chris Just
-
David Abrahams
-
Jody Hagins
-
Robert Ramey