(Final question at the bottom)
Recently, I asked a question concerning how I would fix linker errors (on duplicate symbols concerning multiple definitions of a template void.
Because I was using the functions in multiple source files, I was suggested to use the keyword inline
to allow declarations in the header or put the declarations in a compiled source file.
After I realized that inline
had some bad repercussions, I put my declarations in a source file.
Now this was okay, except for variadic templates:
template<typename T, typename... Args>
void cleanup(T *t, Args&&... args);
I found some apparent solutions - but not to variadic templates - use a .tpp file (but it started declaring duplicate symbols again) or keep the source file and add explicit instantiations.
But void cleanup
has the potential to be used hundreds of combinations of parameters, so I don't want to explicitly instantiate everything.
Question: So, how would I go about either
- Keeping the variadic template definitions in the source file, OR
- Putting definitions in a .tpp file without getting duplicate symbols, and ultimately avoid using
inline
?
Examples of duplicate/undefined symbol errors for .tpp declaration and putting the above template definition in a source file respectively.
duplicate symbol __Z7cleanupI10SDL_WindowJEEvPT_DpOT0_ in:
CMakeFiles/Game.dir/Game/main.cc.o
CMakeFiles/Game.dir/Game/RichTools/rtexture.cc.o
_
Undefined symbols for architecture x86_64:
"void cleanup<SDL_Renderer, SDL_Window*&>(SDL_Renderer*, SDL_Window*&&&)",
referenced from:
cleanQuit() in main.cpp.o
ld: symbol(s) not found for architecture x86_64
inline
then! You mention that you considered its use but that it had "bad repercussions", but what exactly are those?