C++ Gotchas: Code

Source code for non-trivial examples

From the book's preface:

"...code that appears in the text has been edited for brevity and clarity. As a result, the examples as presented often won’t compile without additional, supporting code. The source code for nontrivial examples is available from the author’s Web site: www.semantics.org. All such code is indicated in the text by an abbreviated pathname near the code example, as in gotcha00/somecode.cpp."
 
If, on the other hand, you're looking for source code that accompanies one of Steve's other publications, you'll find it here.
If, on the other hand, you're looking for source code for the Tyr library, you'll find it here.

Download all examples as a zip file

 

Table of Contents for Code Examples

Files actually referenced in the book are listed below in bold; supporting files are in normal font.  The full set of files can be obtained by downloading all the code (see above).  The relative pathname of the file is generally implicit by the gotcha under which it appears.  Therefore, the file array.h in Gotcha #5 can be found in the full source download at gotcha05/array.h.  Note that several files do duty in more than one gotcha, and are sometimes listed with a pathname.  For example, the file myassert.h is referenced in Gotcha #26 as gotcha28/myassert.h and in Gotcha #28 simply as myassert.h.

Gotcha #3:  Global Variables
environment.h
environment.cpp
main.cpp

Gotcha #4:  Failure to Distinguish Overloading from Default Initialization
c12.h
c12.cpp

Gotcha #5:  Misunderstanding References
array.h
main.cpp

Gotcha #7:  Ignorance of Base Language Subtleties
bool.cpp
iter.cpp
main.cpp

Gotcha #8:  Failure to Distinguish Access and Visibility
cbridge.h
cbridge.cpp
main.cpp

Gotcha #11:  Unnecessary Cleverness
select.h
lineno.cpp

Gotcha #14:  Evaluation Order Indecision
e.h
e.cpp
eparse.h
eparse.cpp
main.cpp

Gotcha #24:  Operator -> Subtleties
ptr.h
ptr.cpp

Gotcha #26:  #define Pseudofunctions
execbump.cpp
gotcha28/myassert.h

Gotcha #28:  Side Effects in Assertions
myassert.h
myassert.cpp

Gotcha #32:  Misunderstanding Pointer-to-Pointer-to-Const Conversion
gettoken.cpp

Gotcha #47:  Assignment/Initialization Confusion
rawstorage.h
rawstorage.cpp

Gotcha #53:  Virtual Base Default Initialization
virtassign.cpp

Gotcha #55:  Runtime Static Initialization Order
main.cpp
term.h
term.cpp

Gotcha #56:  Direct vs. Copy Initialization
seqlength.cpp

Gotcha #67:  Failure to Employ Resource Acquisition is Initialization
main.cpp
trace.h
trace.cpp

Gotcha #69:  Type Codes
firewall.h
firewall.cpp
main.cpp
msg1.cpp
msg2.cpp

Gotcha #71:  Hiding Nonvirtual Functions
main.cpp
msg.h
msg.cpp
msgdecorator.h
msgdecorator.cpp

Gotcha #76:  Virtual Assignment
gotcha90/container.h

Gotcha #83:  Failure to Distinguish Aggregation and Acquaintance
cptr.h
ptrlist.h
main.cpp

Gotcha #84:  Improper Operator Overloading
gotcha05/array.h

Gotcha #88:  Misunderstanding Templated Copy Operators
main.cpp
money.h
money.cpp

Gotcha #89:  Arrays of Class Objects
apply.cpp

Gotcha #90:  Improper Container Substitutability
container.h
container.cpp
bondlist.h
bondlist.cpp
list.h
main.cpp

Gotcha #92:  Public Inheritance for Code Reuse
button.h
button.cpp
cptr.h
main.cpp
moreactions.h
 



 
 
Copyright © 2002 by Stephen C. Dewhurst