Is it appropriate to give the Definition of a small Function — which is used by two projects and has up to 10 lines of code — into a Headerfile?
It is because i can put the Headerfile into the include-Directory, which is shared by both Projects. Otherwise i have to maintain the same cpp-Files in each Project Source Directory.
What is the common way for this situation?
Thanks for your answers.
You can put it in a header, but you need to define it as inline:
This will prevent multiple-definition errors if the header is included in two different translation units in the same project. Note that this does not mean that the compiler will necessarily inline the function code at the call site.
Alternatively, you can define it in a nameless namespace, which will make it local to the translation unit(s) you include it in: