IsBaseOf function

I

imre

Hi

Let's suppose we have some metaclass templates. We use object instances
of these as runtime representations of class types. They have some
functions that return informations about the represented classes.

struct Class_
{
virtual bool IsEmpty() const = 0;
};

template <class Cls>
struct Class:
public Class_
{
virtual bool IsEmpty() const { return boost::is_empty<Cls>(); }
};

Easy so far. The problems begin if I want to add a bool
IsBaseOf(Class_* derived) function. Boost has a nice
is_base_and_derived<B, D> template, but I don't know how to dispatch
the call, based on the dynamic types of this and derived, to the
appropriate instance of is_base_and_derived.

By overriding IsBaseOf(), as with IsEmpty(), I can get one of the
types. Now if I could write something like return
derived->IsDerivedFrom<Cls>();, that would be fine, as IsDerivedFrom
could now easily call is_base_and_derived. But of course, it doesn't
work; IsDerivedFrom should be a virtual (we only have a Class_*)
function template, and such thing doesn't exist in C++.

I guess I somehow have to build my own function pointer table, but I
don't really know how. So any help would be appreciated.

Thanks,

Imre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top