We know from Section 1.5 (p. 20) that ordinarily class definitions go into a header file. In this section we’ll see how to define a header file for the Sales_item class.
In fact, C++(www.cppentry.com) programs use headers to containmore than class definitions. Recall that every namemust be declared or defined before it is used. The programswe’ve written so far handle this requirement by putting all their code into a single file. As
long as each entity precedes the code that uses it, this strategy works. However, few programs are so simple that they can be written in a single file. Programs made up of multiple files need a way to link the use of a name and its declaration. In C++(www.cppentry.com) that is done through header files.
To allow programs to be broken up into logical parts, C++(www.cppentry.com) supports what is commonly known as separate compilation. Separate compilation lets us compose a program from several files. To support separate compilation, we’ll put the definition of Sales_item in a header file. The member functions for Sales_item, which we’ll define in Section 7.7 (p. 258),will go in a separate source file. Functions such as main that use Sales_item objects are in other source files. Each of the source files that use Sales_item must include our Sales_item.h header file.