May 1996
Intermediate to advanced
304 pages
5h 54m
English
Some while back I received e-mail from someone in France who was both mystified and a might upset. He had either volunteered or been drafted to provide a persistence library for his project group. In preparation for his work, he coded and then printed out the result of applying the sizeof operator to the following seemingly trivial class hierarchy:
class X {};
class Y : public virtual X {};
class Z : public virtual X {};
class A : public Y, public Z {}; None of these classes contains any explicit data—any anything, in fact, except an inheritance relationship—so he apparently believed the size of each class should be 0. It wasn’t, of course—not even the apparently benign class X:
sizeof X yielded 1 sizeof Y yielded ...
Read now
Unlock full access