[英]C++ why we include all declarations in header files
#include <iostream>
当你这样做并且它成为通过预处理器的源时,我们的文件将为 5k。 编译器不会做所有这些声明,对吧? (总有一些东西我们终究用不到)
| linker 或编译器是否阻止了这种情况?
**所以当您在 header 中包含所有声明文件时 **
编译器只看到声明,因为它知道定义可能在某处,然后它在链接时使用所有定义。
经验法则是:Header 文件应包含声明,源文件应包含定义。
两种类型的声明:
extern int y; // declares y, but does not define it. y is defined elsewhere,
// but the program can now use it since it knows what it is (an integer)
double someFunction( double, int );
参考自: http://www.cplusplus.com/articles/yAqpX9L8/
也可在此站点上获取更多信息: http://www.cplusplus.com/articles/Gw6AC542/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.