游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2952|回复: 5

头文件的包含有什么规则?

[复制链接]

3

主题

32

帖子

36

积分

注册会员

Rank: 2

积分
36
发表于 2007-10-21 09:44:00 | 显示全部楼层 |阅读模式
头文件的包含要按什么规则?为什么有的时候要放在其它头文件的前面,有时候多个文件包含某个头文件就会说xx符号重定义...

像visual leak detector 10 的文档中有下面这样一段话, 而且<vld.h>被多个文件包含时,会出现 "xx符号在xxx.obj中已经定义" 的情况
In the source file containing your program's main entry point, include the vld.h header file. It's best, but not absolutely required, to include this header before any other header files, except for stdafx.h. If the source file includes stdafx.h, then vld.h should be included after it.

重点是其中的这句 "to include this header before any other header files"

而visual leak detector 19d 而又这样说
Note: Unlike earlier versions of VLD, it is now acceptable to include vld.h in every source file, or to include it in a common header that is included by many or all source files. Only one copy of the VLD code will be loaded into the process, regardless of how many source files include vld.h.


这是为什么?

86

主题

2251

帖子

2384

积分

金牌会员

Rank: 6Rank: 6

积分
2384
QQ
发表于 2007-10-21 17:44:00 | 显示全部楼层

Re:头文件的包含有什么规则?

在头文件的头部加上
#ifndef XXX_H
#define XXX_H
尾部加上
#endif

XXX不同的头文件要不同

3

主题

32

帖子

36

积分

注册会员

Rank: 2

积分
36
 楼主| 发表于 2007-10-22 10:02:00 | 显示全部楼层

Re: Re:头文件的包含有什么规则?

funcman: Re:头文件的包含有什么规则?

在头文件的头部加上
#ifndef XXX_H
#define XXX_H
尾部加上
#endif

XXX不同的头文件要不同


这个我早知道了

30

主题

109

帖子

114

积分

注册会员

Rank: 2

积分
114
发表于 2007-10-22 12:02:00 | 显示全部楼层

Re:头文件的包含有什么规则?

恩,那你八成是在某个头文件忘加了。
加了基本没问题,即使是多个头文件都包括该头文件。

0

主题

34

帖子

46

积分

注册会员

Rank: 2

积分
46
QQ
发表于 2007-10-22 14:23:00 | 显示全部楼层

Re:头文件的包含有什么规则?

头文件加上#pragma once就可

20

主题

222

帖子

276

积分

中级会员

Rank: 3Rank: 3

积分
276
发表于 2007-10-23 22:37:00 | 显示全部楼层

Re:头文件的包含有什么规则?

两段描述矛盾是因为不同版本之故吧,如何包含视乎使用的版本
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-6-20 04:07

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表