However, when I try to compile I get the following linker errors:
1>main.obj : error LNK2005: "double __cdecl str_to_T<double>(char const * const)" (??$str_to_T@N@@$$FYANQBD@Z) already defined in fun_load_training_data.obj
1>main.obj : error LNK2005: "double __cdecl str_to_T<double>(char const * const)" (??$str_to_T@N@@YANQBD@Z) already defined in fun_load_training_data.obj
1>lib_tools.obj : error LNK2005: "double __cdecl str_to_T<double>(char const * const)" (??$str_to_T@N@@$$FYANQBD@Z) already defined in fun_load_training_data.obj
1>lib_tools.obj : error LNK2005: "double __cdecl str_to_T<double>(char const * const)" (??$str_to_T@N@@YANQBD@Z) already defined in fun_load_training_data.obj
1>struct_horizon_value.obj : error LNK2005: "double __cdecl str_to_T<double>(char const * const)" (??$str_to_T@N@@$$FYANQBD@Z) already defined in fun_load_training_data.obj
1>struct_horizon_value.obj : error LNK2005: "double __cdecl str_to_T<double>(char const * const)" (??$str_to_T@N@@YANQBD@Z) already defined in fun_load_training_data.obj
Now, fun_load_training_data.h/.cpp contain nothing more than a single function declaration (not for str_to_T of course), and a #include of lib_tools.h (where str_to_T is defined). lib_tools.h is properly header guarded (checked it thrice), so what else could be causing this issue? I tried a clean/rebuild but that didn't help...
Once you specialize it, it's no longer a template and is an actual function. Therefore normal function rules apply (inline or have the body in only one source file)
Inline functions are allowed to be multiply defined because the compiler needs the function body in the source file that is calling it in order to inline it.