On Sep 16, 8:29 pm, red floyd <no.s...@here.dude> wrote:
> puzzlecracker wrote:
> > I am kind of confused with the vpointer. Assuming the class has a
> > virtual function. Would ONE pointer (occupying 16 bits) to virtual
> > table be create for the class or One for each object? How does this
> > pointer fit into aligment properties of an object (of the class) or
> > class itself?
>
> An implementation is not required to provide a vptr or a vtbl. Most
> implementations use them, but they are not required to.
>
> If your implementation uses vptr, it would be the natural pointer size
> for your platform (most likely *NOT* 16 bits), and each object of that
> class would have the vptr. There would be one vtbl for each class, and
> each object of that class would point to that vtbl.
>
> For details of how a vptr/vtbl model works, see Lippman's "Inside the
> C++ Object Model".
Seems like an overhead, to have one pointer per object, that can
possibly be avoided. All object pointers to a specific derived type
have pointer to the same virtual table. Perhaps we can store that
pointer (as static variable or external) that each object of that
derived class can see/use. Is such construct available or can be
simulate it in C++? Agh, it is really a compiler issue.
Thanks