The Wikipedia article on interfaces states:

At the execution level, the classical scheme of multiple inheritance causes an additional series of inconveniences:

- if an object can inherit n classes in parallel, there are n independent ways to access it, and therefore there must be (n - 1) additional pointers to it; from the point of view of automatic memory management, this will mean that there are links pointing to the middle of the object;

What does “links pointing to the middle of an object” mean, that is, to the middle of that part of the allocated physical memory that the object occupies?

    1 answer 1

    Imagine the situation. We have a simple class:

    class A{ int x; } class B{ int y; } class C:A,B{ } 

    We know that a pointer to an heir can be led to a pointer to a base class. Those.

     C* p = new C(); //p - p = 0; A* pp = (A*) p; //pp -p = 0; 

    There are no problems here, the base class lies at the beginning of the object, the pointer (its numeric value) is the same.

    Now B* ppp = (B*) p; //ppp - p = sizeof(A) B* ppp = (B*) p; //ppp - p = sizeof(A) .

    We must have a pointer to the beginning of the block B - class. But he goes after the block of class A.

    This is of course a bit simplified, but about the same is. Those. object C is object A, then object B, then its fields.

    C ++ example .

    • So, the pointer (link) to the object C we bring to the pointers to the base classes - A and B, and in the order of their reduction we come to the conclusion that the "link to the middle of the object (C)" is the pointer (link) to the object B? - TimurVI
    • @ TimurValiyev can say so. - pavel
    • and what then, in the context of what was said, would it be convenient (just to reverse the problem) of multiple inheritance? What should be referred to? - TimurVI