|
|
|
|
|
|
|
WHY USE THE COMPILER TO CATCH ERRORS? The harsh reality of programming is that none of us writes perfectly bug-free code. What separates the professional from the hobbyist is not that the professional's code is perfect; it is that the bugs are found before the product ships, not after. |
|
|
|
| | Compile-time errorsthat is, errors found while you are compilingare far better than run-time errorserrors found while you are executing the program. | | Compile-time errors can be found much more reliably. It is possible to run a program many times without going down every possible code path. Therefore, a run-time error can hide for quite awhile. Compile-time errors are found every time you compile, so they are easier to identify and fix. It is the goal of quality programming to ensure that the code has no run-time bugs. One tried-and-true technique to accomplish this is to use the compiler to catch your mistakes early in the development process. | | Of course, your code can be perfectly legal but not do what you intend. That is why you still need a Quality Assurance team. |
|
|
|
|
|
Where to Put Class Declarations and Method Definitions |
|
|
|
|
|
|
|
|
Each function that you declare for your class must have a definition. The definition is also called the function implementation. Like other functions, the definition of a class method has a function header and a function body. |
|
|
|
|
|
|
|
|
The definition must be in a file that the compiler can find. Most C++ compilers want that file to end with .C, or .CPP. This book uses .CPP, but check your compiler to see what it prefers. |
|
|
|
|
|
|
|
|
Many compilers assume that files ending with .C are C programs, and that C++ program files end with .CPP. You can use any extension, but .CPP will minimize confusion. |
|
|
|
|
|
|
|
|
|
You will need to add these .CPP files to your project or makefile. How you do this will depend on your compiler. If you are using an integrated development environment, look for a command such as add files to project. Every .CPP file for your program must be added to the project so that it will be compiled and linked into the final executable. |
|
|
|
|
|