Staying in Touch ............................................................................................
If you have comments, suggestions, or ideas about this book or other books, I’d love to
hear them. Please contact me through my Web site: http://www.libertyassociates.com. I look
forward to hearing from you.
786 Day 21
DOlook at other books. There’s plenty
to learn and no single book can teach
you everything you need to know.
DOjoin a good C++ user group.
DON’Tjust read code! The best way to
learn C++ is to write C++ programs.
DO DON’T
Summary ..............................................................................................................
Today, you learned more details about working with the preprocessor. Each time you run
the compiler, the preprocessor runs first and translates your preprocessor directives such
as #defineand #ifdef.
The preprocessor does text substitution, although with the use of macros these can be
somewhat complex. By using #ifdef,#else, and #ifndef, you can accomplish condi-
tional compilation, compiling in some statements under one set of conditions and in
another set of statements under other conditions. This can assist in writing programs
for more than one platform and is often used to conditionally include debugging
information.
Macro functions provide complex text substitution based on arguments passed at compile
time to the macro. It is important to put parentheses around every argument in the macro
to ensure the correct substitution takes place.
Macro functions, and the preprocessor in general, are less important in C++ than they
were in C. C++ provides a number of language features, such as constvariables and
templates, that offer superior alternatives to use of the preprocessor.
You also learned how to set and test individual bits and how to allocate a limited number
of bits to class members.
Finally, C++ style issues were addressed, and resources were provided for further study.