2014.4.14
参考材料:C++ Primer 5th edition(6.1.2, 6.1.3)
1:原因 "When we use header files for our function declarations, we can ensure that all the declarations for a given function agree. Moreover, if the interface to the function changes, only one declaration has to be changed."
就是说,如果我们把函数的声明放入头文件,当要在某个source file中使用这个函数时,先包含这个头文件即可。这样一来可以确保每个使用这个函数声明的地方声明都是一样的,二来如果函数的声明改动了,我们只需要改变头文件中的声明。
2:将函数声明与实现分离,而且不产生错误的具体做法。
一,将函数声明放入header;
二,在使用这些函数的source file中包含这个头文件;
三,在实现这些函数的source file中也要包含这个头文件。
3:能不能将函数的实现放入头文件呢?(暂时不明白)
class的实现是放在header里的(2.6.3)
相关理解:
http://bbs.csdn.net/topics/230023815(意思是compiler会根据一些设置去找具体的implementation,解决我的问题是不用在使用函数的地方包含实现这些函数的source file)
http://www.cnblogs.com/nzbbody/p/3454548.html(意思是C++对每个cpp文件单独编译,每个cpp生成obj,然后连接成exe)