Re: The C++ Object Model: Good? Bad? Ugly?
On Nov 6, 11:36 pm, tonytech08 <tonytec...@gmail.com> wrote:
On Nov 4, 3:08 am, James Kanze <james.ka...@gmail.com> wrote:
On Nov 4, 5:51 am, Ian Collins <ian-n...@hotmail.com> wrote:
[...]
An instance of a polymorphic class has to contain
information about its type, so it can't be the same as a
POD class. Constructors and (non-virtual) methods are
irrelevant.
Just a nit, but it's possible to implement polymorphism with
no additional information in the instance itself; you could,
for example, maintain the information is a separate
hashtable which mapped the address to the type information.
What isn't possible is to establish this mapping without
executing some code. I.e. a constructor.
And how relatively (relative to the current implementation)
slow would that be is the question.
I don't think anyone actually knows, since as far as I know, no
one has actually implemented it this way. A virtual table
look-up involves two indirections---read the vptr, then the vtbl
itself; it seems pretty obvious that a hash table implementation
can't come close. It might be useful, however, for
instrumenting the code, in order to generate various statistics,
or even doing some additional error checking on the side
(although I'm not sure what).
As I said above, my comment was just a nit---it's possible to
implement polymorphism with no information about the type in the
class object itself. Conceptually, at least; it's probably not
practical.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34