[   ^ to index...   |   <-- previous ]

Managing multi-file projects

Any non-trivial piece of software will involve many files. A group of files that makes up a single program is referred to as a "project" in some development environments. Here's how to work with projects in MSVC:

  1. Create a project using "File --> New..." and selecting a project type. The project type for most of this course's assignments, if not all, will be "Win32 Console Application".


  2. To add files to your project, go under the "Projects --> Add to Project --> New..." or "Projects --> Add to Project --> Files" menus.


  3. You can then use the Build menu to build the entire application or to compile specific files as needed. Compiling a specific file is useful if you just want to check it for syntax.

Include guards

Sometimes when you are using multiple files, the problem of multiple inclusion will arise. Sometimes bad things will happen if you #include a file more than once in a single other file (this can happen if one header includes some other header file for its own purposes). To get around this problem, we use include guards:

#ifndef __MYMATH_HPP__ #define __MYMATH_HPP__ // the text of the include file goes here #endif

The #ifndef __MYMATH_HPP__ line tells the C++ preprocessor to include what follows only if the given symbol (in this case, __MYMATH_HPP__) is not a defined preprocessor symbol.

The #define __MYMATH_HPP__ defines the given symbol. It has no value, but it is defined.

The #endif closes the preprocessor #ifndef statement.

From now on, you should use include guards on all your headers, regardless of whether you think there's any danger of multiple inclusion.


Last modified: Wed Jun 21 20:33:14 PDT 2000