RE: [GD-General] Multiple Inheritance and RTTI
Brought to you by:
vexxed72
|
From: <phi...@pl...> - 2003-02-05 19:36:02
|
Alex Lindsay <ali...@au...>:
> As far as I understand it, every polymorphic class is going to have a
unique vtable pointer, and while it's compiler dependent, my experience is
that the vtable pointer tends to be the first "member" data in every
instance.
DANGER!
This assumption is not true for gcc, unless all of the classes you're
making this assumption for have a virtual function in their root base
class. For gcc, at least the versions I'm familiar with, the vtable is the
first item in the first class in the heirarchy with a virtual function.
To take Peter's example:
struct X
{
int x;
};
struct Y: public X
{
virtual ~Y();
};
In gcc, the vtable would be the second member in raw memory.
Other than that, it's a nice, if not particularly portable, idea.
Personally I'd like to have formal access to the vtable pointer (and the
corresponding labels exposed), so you could do precisely this sort of
'quick and dirty' hand rolled RTTI. The standard RTTI scheme is, IMHO a
bit, all or nothing, and with all being expensive overkill in many cases,
nothing is what you usually get.
Cheers,
Phil
|