< previous page page_438 next page >

Page 438
Access
The way you access portions of your program should also be consistent. Some tips for access include these:
Always use public:, private:, and protected: labels; don't rely on the defaults.
List the public members first, then protected, then private. List the data members in a group after the methods.
Put the constructor(s) first in the appropriate section, followed by the destructor. List overloaded methods with the same name adjacent to each other. Group accessor functions together when possible.
Consider alphabetizing the method names within each group and alphabetizing the member variables. Be sure to alphabetize the filenames in include statements.
Even though the use of the virtual keyword is optional when overriding, use it anyway; it helps to remind you that it is virtual, and also keeps the declaration consistent.
Class Definitions
Try to keep the definitions of methods in the same order as the declarations. It makes things easier to find.
When defining a function, place the return type and all other modifiers on a previous line so that the class name and function name begin on the left margin. This makes it much easier to find functions.
include Files
Try as hard as you can to keep from including files into header files. The ideal minimum is the header file for the class that the current class derives from. Other mandatory includes will be 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.
All header files should use inclusion guards.

 
< previous page page_438 next page >

If you like this book, buy it!