Re: Specifying base class order with multiple inheritance?
On Jul 31, 8:31 am, alan <almkg...@gmail.com> wrote:
I'd like to know if there was some way I could assure the
order of base classes.
[...]
So, I'm wondering two things:
1. is my solution above at all crazy?, and
I'm not sure I fully understand it, but...
2. can I ensure that the Generic base is at the start of the
object?
No. There are absolutely no guarantees with regards to how the
compiler lays out base classes in objects.
I would assume that if Generic and derived-only-from-Generic
is listed as the first class in the inheritance list, it would
be positioned to the start of the object.
In some implementations, that might be, provided no virtual
inheritance is involved (although in a scheme like yours,
virtual inheritance will almost certainly be involved at some
point). But it's certainly not guaranteed, and I believe that
there are (or were) some compilers that put the base class after
the first derived class. (I think the goal was to get the
object pointer pointing to the middle of the object, so you
could use negative offsets, as well as positive, and have bigger
objects with the offset only a byte.)
--
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