If you define a function in the global namespace in a C++ header file and encounter linker errors (complaining about the function already defined elsewhere), there’s a simple fix! Simply mark the function as inline
. This will prevent the duplication of the function in other source files.
Note that using inclusion guards does not solve this problem and you must define the function as inline
.
Recent Comments