Sams Teach Yourself C++ in 21 Days

(singke) #1

includeFiles ..................................................................................................


Try as hard as you can to minimize the use of #include, and thus minimize the number
of files being included in header files. The ideal minimum is the header file for the class
from which this one derives. Other mandatory includes are those for objects that are
members of the class being declared. Classes that are merely pointed to or referenced
only need forward references of the form.
Don’t leave out an include file in a header just because you assume that whatever .cpp
file includes this one will also have the needed include. And don’t add extra ones to try
to “help out” other included files.

784 Day 21


TIP All header files should use inclusion guards.

Using assert()..............................................................................................


You learned about assert()earlier today. Use assert()freely. It helps find errors, but it
also greatly helps a reader by making it clear what the assumptions are. It also helps to
focus the writer’s thoughts around what is valid and what isn’t.

Making Items Constant with const................................................................


Use constwherever appropriate: for parameters, variables, and methods. Often, there is
a need for both a constand a non-constversion of a method; don’t use this as an excuse
to leave one out. Be very careful when explicitly casting from constto non-constand
vice versa (at times, this is the only way to do something), but be certain that it makes
sense, and include a comment.

Next Steps in Your C++ Development ................................................................


You’ve spent three long, hard weeks working at C++, and you are likely to have the
basics needed to be a competent C++ programmer, but you are by no means finished.
There is much more to learn and many more places you can get valuable information as
you move from novice C++ programmer to expert.
The following sections recommend a number of specific sources of information, and
these recommendations reflect only personal experience and opinions. Dozens of books
and thousands of articles are available on each of these topics, however, so be certain to
get other opinions before purchasing.
Free download pdf