第三天学习(header file/declaration & definition)

# :preprocess
declaration:声明,指function name
definition:定义,指function body

header file
# progma once:避免我们在同一个translation unit(即.cpp file) 里重复引用
header file(.h) 里放置所有函数的声明,便于在不同.cpp file 中调用其他.cpp file内的函数。

# ifndef _LOG_H
#define _LOG_H

中间写header file 的declaration

# endif

这一段preprocess是为了防止.h文件之间包含了其他.h文件里的声明,重复引用会报错。

以上两个preprocess等价

在这里顺便提到preprocessor 的两种符号
1、#include <iostream>
2、#include "log.h"
<>: 是拷贝iostream 到当前.cpp file
“”:内包含的文件是和当前.cpp file 路径相关的。

“”在任何情况下都可以使用,但是最好的情况是use it only for relative part, and use <> for compile part.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容