dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #16489
Re: Multiple inheritance
Anders Logg wrote:
>>> I've narrowed one of the problems down to the following simple
>>> example. Say that a class C inherits from both A and B (which both
>>> have member variables - this is important). Then I would expect an
>>> object c of class C to have the same address/pointer as seen from all
>>> three classes.
>> It could not possibly work this way because B must be able to function
>> correctly with no knowledge of A and C.
>
> I don't understand why that would not work. It looks to me like it's
> just some trick to simplify the cast from a C to a B, and that cast is
> handled by an offset in the struct.
Static casts are eliminated at compile time, they can't allocate memory
to make copies of the data structure. The definition of a struct
completely determines it's layout in memory. The definition
class B
{
public:
B() { cout << "B pointer: " << this << endl; }
int bvar;
};
requires a particular layout, specifically sizeof B == sizeof bvar and
offsetof(B,bvar) == 0. If you give me a pointer to one of these things,
I have to be able to use it this way. The same applies to A, therefore
it is not possible for (void*)(A*)&c == (void*)(B*)&c.
Jed
Attachment:
signature.asc
Description: OpenPGP digital signature
Follow ups
References