c++头文件
2015-11-12 07:57
309 查看
C++程序设计(c++头文件)
Definition of a class
In C++,separated .h and .cpp files are used to define one classclass declaration(声明) and prototypes(原型) in that class are in the header file(.h)
All the bodies of these function are in the source file(.cpp).
include叫做编译预处理
示例1
a.h的代码#ifndef A //如果没有定义宏,则定义这个宏 #define A using namespace std; void show(){ cout<<"hello world"<<endl; } #endif // A
main.cpp的代码
#include<iostream> #include"a.h" using namespace std; int main(){ show(); }
结果
hello world
Declarations vs. Definition
A.cpp file is a compile unitonly declarations are allowed to be in .h
1.extern
2.functionprototypes
3.class/struct declaration
Tips for header
1.One class declaration per header file2.Associated with one source file in the same prefix of name.
3.The contents of a header file is surrounded with
#ifndef #define #endif
相关文章推荐
- 如何写好 C main 函数
- Lua和C语言的交互详解
- 关于C语言中参数的传值问题
- 简要对比C语言中三个用于退出进程的函数
- 深入C++中API的问题详解
- 基于C语言string函数的详解
- C语言中fchdir()函数和rewinddir()函数的使用详解
- C语言内存对齐实例详解
- 使用C语言判断英文字符大小写的方法
- c语言实现的带通配符匹配算法
- C语言实现顺序表基本操作汇总
- C语言中计算正弦的相关函数总结
- 使用C语言详解霍夫曼树数据结构
- 探讨C语言的那些小秘密之断言
- C语言实现BMP转换JPG的方法
- 深入探讨C语言中局部变量与全局变量在内存中的存放位置
- C语言查找数组里数字重复次数的方法
- C语言泛型编程实例教程
- C语言中使用lex统计文本文件字符数
- 在C语言中转换时间的基本方法介绍