Reputation: 29724
in Bjarne's "C++..." I have just read that
the way most C++ implementations work implies that a change in the size of a base class requires a recompilation of all derived classes
$12.4.3 p.318
in the size? or rather change in general?
Upvotes: 2
Views: 104
Reputation: 490108
In the typical case, a change in size requires re-compiling all derived classes. Other changes can require re-compiling derived classes as well (e.g., changing the order and/or type of members can require re-compilation, even if the size remains constant).
I think most of what Bjarne was trying to get at is that derivation is typically implemented as aggregation from the viewpoint of memory layout. For example, if you start with something like:
struct A {
int x;
int y;
};
struct B : A {
int a;
int b;
};
B b;
The memory layout of b
will look like:
| X | Y | a | b |
...so when/if the size of A
changes, the members of B
will be stored at different offsets in the composite object.
With a typical build system, any change to the header that contains the base class definition will result in re-compiling all derived classes, regardless of whether the change would require recompilation or not though (i.e., if the header has a more recent change date than a source file that depends on it, the source file will be re-compiled, even if all that's changed is, say, a comment that makes no difference in the code at all).
Upvotes: 4