[97] This is another example coached by Nathan Myers.
[98] For a detailed explanation of this oddity, see Items 6 and 29 in Scott Meyer’s
[99] We revisit multi-threading issues in Chapter 11.
[100] Chuck designed and provided the original reference implementations for bitset and also bitstring, the precursor to vector
[101] They will likely appear in the next revision of Standard C++.
[102] Available at http://www.sgi.com/tech/stl.
[103] As we explained earlier, the vector
[104] With Microsoft’s compilers you will have to enable RTTI; it’s disabled by default. The command-line option enable it is /GR.
[105] Compilers typically insert a pointer to a class’s RTTI table inside of its virtual function table.
[106] A dynamic_cast
[107] Even more importantly, we don’t want undefined behavior. It is an error for a base class not to have a virtual destructor.
[108] The actual layout is of course implementation specific.
[109] But not detected as an error. dynamic_cast, however can solve this problem. See the next chapter for details.
[110] Compilers can add arbitrary padding, so the size of an object must be at least as large as the sum of its parts, but can be larger.
[111] We use the term
[112] The presence of these pointers explains why the size of b is much larger than the size of four integers. This is (part of) the cost of virtual base classes. There is also VPTR overhead due to the virtual constructor.
[113] Note that the virtual inheritance is crucial to this example. If Top were not a virtual base class, there would be multiple Top subobjects, and the ambiguity would remain. Dominance with multiple inheritance only comes into play with virtual base classes.
[114] Jerry Schwarz, the author of IOStreams, has remarked to both of us on separate occasions that if he had it to do over again, he would probably remove MI from the design of IOStreams and use multiple stream buffers and conversion operators instead.
[115] A phrase coined by Zack Urlocker.
[116] Also known as the "Gang of Four" book (GoF). Conveniently, the examples are in C++.
[117] The C++ standards states: "No translation unit shall contain more than one definition of any variable, function, class type, enumeration type or template… Every program shall contain exactly one definition of every non-inline function or object that is used in that program."
[118] This is known as Meyers’ Singleton, after its creator, Scott Meyers.
[119] Andrei Alexandrescu develops a superior, policy-based solution to implementing the Singleton pattern in
[120] For more information, see the article "Once is Not Enough" by Hyslop and Sutter in the March 2003 issue of
[121] For up-to-date information, visit http://hillside.net/patterns.
[122]James O. Coplien,
[123] It differs from Java in that java.util.Observable.notifyObservers( ) doesn't call clearChanged( ) until after notifying all the observers
[124] There is some similarity between inner classes and
[125] Much of this chapter began as a translation from the
[126] This is an oversimplification. Sometimes even when it seems like an atomic operation should be safe, it may not be, so you must be very careful when deciding that you can get away without synchronization. Removing synchronization is often a sign of premature optimization – things that can cause you a lot of trouble without gaining much. Or anything.
[127] This is in contrast to Java, where you must hold the lock in order to call notify() (Java’s version of signal()). Although Posix threads, on which the ZThread library is loosely based, do not require that you hold the lock in order to call signal() or broadcast(), it is often recommended.