Topic: Standard for order of base-class specification?


Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Sat, 5 Mar 1994 15:35:13 GMT
Raw View
holcomb@wg.com (Edgar Holcomb) writes:

>Is it dangerous to assume the structure of an instance of a
>class with multiple base classes based on the order in which
>the base classes are specified?

Yes.

>Is it safe to assume that, within the
>Derived object, the BaseA sub-object will be at offset zero
>and the BaseB sub-object will be at offset sizeof( BaseA )?

No.

>I don't know if the language defines this, or if it's
>compiler specific.

It's highly implementation-dependant.

--
Fergus Henderson - fjh@munta.cs.mu.oz.au




Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Mon, 7 Mar 1994 09:34:06 GMT
Raw View
In article <HOLCOMB.94Feb28155855@donald.wg.com> holcomb@wg.com (Edgar Holcomb) writes:
>
>Hi, folks,
>
>Is it dangerous to assume the structure of an instance of a
>class with multiple base classes based on the order in which
>the base classes are specified?
>
>Recall that, given a class specified as
>
>class Derived : public BaseA, public BaseB
>{};
>
>an instance of Derived would contain a BaseA sub-object and
>a BaseB sub-object.  Is it safe to assume that, within the
>Derived object, the BaseA sub-object will be at offset zero
>and the BaseB sub-object will be at offset sizeof( BaseA )?

I don't believe so.  As a matter of fact, I don't believe that it is
even defined whether the `BaseA' part is *below* the `BaseB' part or
not.

If anyone else knows different, please speak up.

--

-- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting -------------------
---- domain addr: rfg@netcom.com ----------- Purveyors of Compiler Test ----
---- uucp addr: ...!uunet!netcom!rfg ------- Suites and Bullet-Proof Shoes -




Author: holcomb@wg.com (Edgar Holcomb)
Date: 28 Feb 1994 20:58:55 GMT
Raw View
Hi, folks,

Is it dangerous to assume the structure of an instance of a
class with multiple base classes based on the order in which
the base classes are specified?

Recall that, given a class specified as

class Derived : public BaseA, public BaseB
{};

an instance of Derived would contain a BaseA sub-object and
a BaseB sub-object.  Is it safe to assume that, within the
Derived object, the BaseA sub-object will be at offset zero
and the BaseB sub-object will be at offset sizeof( BaseA )?

I don't know if the language defines this, or if it's
compiler specific.

Thanks in advance!

-Edgar




Author: b91926@fsgi01.fnal.gov (David Sachs)
Date: 1 Mar 1994 00:04:22 -0600
Raw View
holcomb@wg.com (Edgar Holcomb) writes:


>Hi, folks,

>Is it dangerous to assume the structure of an instance of a
>class with multiple base classes based on the order in which
>the base classes are specified?

>Recall that, given a class specified as

B
>class Derived : public BaseA, public BaseB
>{};

>an instance of Derived would contain a BaseA sub-object and
>a BaseB sub-object.  Is it safe to assume that, within the
>Derived object, the BaseA sub-object will be at offset zero
>and the BaseB sub-object will be at offset sizeof( BaseA )?

>I don't know if the language defines this, or if it's
>compiler specific.

The language DOES NOT define this; it is compiler specific.
It is quite likely that the offset of BaseB will NOT be
sizeof (BaseA), especially if there a virtual functions.