.h file and function realization

If we define a function in a .h file, compilating will succeed but

every quoting cpp file will generate a part of .obj which realize this function.

 

So Compile is OK  but Link will error out at multiple definition of a same function.

 

Conclusion is that :  Function Declaration can be written in .h file.

           Never Function Definition be written in .h file. 

 

 

The same reason,  Never Variable Definition Be Written in .h file.

 

We can write them in .cpp as a global variable.

posted @ 2016-08-11 16:58  steven_xiu  阅读(122)  评论(0编辑  收藏  举报