If my projects consist of two translation units a.cpp and b.cpp, and there is h.cpp that have a function definition. In this case, each .cpp file will be successfully compiled, but we will get multiple definitions at the linking stage. To avoid this (if you don’t put the definition in a separate .cpp file), you can make this function
- inline
- static
- static inline
- surround it with an empty namespace
Can someone explain the difference between these four approaches, which is better to use. And what will happen if it is an template function, will there be any problems?