设为首页 加入收藏

TOP

2.9 Writing Our Own Header Files
2013-10-07 15:23:52 来源: 作者: 【 】 浏览:65
Tags:2.9 Writing Our Own Header Files

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.

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇2.9.1 Designing Our Own Headers.. 下一篇2.1 Primitive Built-in Types

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Sphinx : 高性能SQL (2025-12-24 10:18:11)
·Pandas 性能优化 - (2025-12-24 10:18:08)
·MySQL 索引 - 菜鸟教 (2025-12-24 10:18:06)
·Shell 基本运算符 - (2025-12-24 09:52:56)
·Shell 函数 | 菜鸟教 (2025-12-24 09:52:54)