Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-03-01 10:34:31


Chris Just <cpjust_at_[hidden]> 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

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk