In This Chapter
Enabling all warnings and error messages
Using a clear and consistent coding style
Limiting the visibility
Adding comments to your code while you write it
Single-stepping every path at least once
Avoiding overloaded operators
Using exceptions to handle errors
Use static assertions
Avoiding multiple inheritance
In this chapter, I look at several ways to minimize errors, as well as ways to make debugging the errors that are introduced easier.
The syntax of C++ allows for a lot of error checking. When the compiler encounters a construct that it can't decipher, it has no choice but to generate an error message. Although the compiler attempts to sync back up with the next statement, it does not attempt to generate an executable program.
Disabling warning and error messages is a bit like unplugging the Check Engine light on your car dashboard because it bothers you: Ignoring the problem doesn't make it go away. If your compiler has a Syntax Check from Hell mode, enable it.
Don't start debugging your code until you remove or at least understand all warnings generated during compilation. Enabling all warning messages if you then ignore them does you no good. If you don't understand the warning, look it up. What you don't know will hurt you.
Coding in a clear and consistent style not only enhances the readability of your program but also ...