Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is multiple inheritance, and there are two inherited functions with the same signature, <strong>both of which have implementation</strong>. That's where C++ is different from Java.</p> <p>Calling <code>write</code> on an expression whose static type is <code>MyBigClass</code> would therefore be ambiguous as to which of the inherited functions was desired.</p> <p><strike>If <code>write</code> is only called through base class pointers, then defining <code>write</code> in the derived class is NOT necessary, contrary to the claim in the question.</strike> Now that the question changed to include a pure specifier, implementing that function in the derived class is necessary to make the class concrete and instantiable.</p> <p><code>MyWriter::write</code> cannot be used for the virtual call mechanism of <code>MyBigClass</code>, because the virtual call mechanism requires a function that accepts an implicit <code>IWriter* const this</code>, and <code>MyWriter::write</code> accepts an implicit <code>MyWriter* const this</code>. A new function is required, which must take into account the address difference between the <code>IWriter</code> subobject and the <code>MyWriter</code> subobject.</p> <p>It would be theoretically possible for the compiler to create this new function automatically, but it would be fragile, since a change in a base class could suddenly cause a new function to be chosen for forwarding. It's less fragile in Java, where only single inheritance is possible (there's only one choice for what function to forward to), but in C++, which supports full multiple inheritance, the choice is ambiguous, and we haven't even started on diamond inheritance or virtual inheritance yet.</p> <p>Actually, this problem (difference between subobject addresses) is solved for virtual inheritance. But it requires additional overhead that's not necessary most of the time, and a C++ guiding principle is "you don't pay for what you don't use".</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload