Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The standard is not concerned with binary compatibility. It is concerned though with classes, and by "changing" the definition of a class from one translation unit to another you indeed invoke undefined behavior.</p> <p>Most compilers do allow a number of changes without the need for recompilation, however the list is small... and for this one I would say that it might not be possible, <em>depending on the a priori knowledge of the derived classes</em>.</p> <p>The problem I foresee lies with the optimization that compilers usually carry out on the virtual tables.</p> <p>When you create a class with virtual functions, you get a virtual table that looks like so:</p> <pre><code>// B virtual table 0 - Offset to complete object 1 - RTTI 2 - func0 3 - func1 ... </code></pre> <p>In order to gain some space, the derived class own virtual functions are usually "appended":</p> <pre><code>// D virtual table Same as B N+3 - func(N+1) N+4 - func(N+2) </code></pre> <p>This way a <code>D</code> object only has one virtual pointer, than can be used as such even when the type is (statically) a <code>B</code> (through pointer or reference).</p> <p>However, if you were to extend <code>B</code> without recompiling <code>D</code>, then it would just plain crash, since when calling the <code>N+1</code> function of <code>B</code> you would instead call the <code>N+1</code> function of <code>D</code> which would probably not even have the same arguments... oups!</p> <p>It can be done, though, if you <strong>know</strong> than no derived class add any virtual function of its own.</p>
    singulars
    1. This table or related slice is empty.
    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. 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