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.
时间: 2024-10-04 14:08:48