随笔 - 17  文章 - 0 评论 - 4 
<2010年5月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

常用链接

留言簿(1)

随笔档案(17)

文章分类

搜索

  •  

最新评论

阅读排行榜

评论排行榜

#pragma once 是C/C++的预处理指令,非标准但很常用;主要功能是保证每次编译时候当前文件只包含一次。功能与定义宏来避免重复包含一样。使用举例:
grandfather.h
#pragma once
 
struct foo {
    
int member;
}
;

father.h
#include "grandfather.h"

child.h
#include "grandfather.h"
#include 
"father.h"

与宏定义相比,#pragma once加快了编译速度,编码更少,避免宏定义名称冲突;但是有些编译器不支持,用
#pragma once会导致代码移植困难。两种方式同时使用解决这些问题:
#pragma once
#ifndef GRANDFATHER_H
#define GRANDFATHER_H
 
struct foo
{
    
int member;
}
;
 
#endif /* GRANDFATHER_H */

参考:
http://en.wikipedia.org/wiki/Pragma_once
posted on 2010-05-30 09:00 鸡蛋捞面 阅读(170) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。