MosaicFuneral
Posting Virtuoso
1,691 posts since Nov 2008
Reputation Points: 888
Solved Threads: 116
Not for template functions (and classes).
A template function are the instructions to the compiler on how to write the function given the parameter types... the template of the function.
When the compiler compiles your code and sees a call to a template function it looks up the template function and uses it to create an actual function that it compiles into the object for the file.
However the compiler works on a single file at a time. If the template function is not defined somewhere in the file being compiled the compiler can not create a real function from the template when it sees the function call because it can not see the template.
So the definition of the template function needs to be visible to the compiler when it is compiling your file there are 2 ways of doing this
Put the definitions of the template functions in the header.
Put the definitions of the template functions in a different file, NOTE not a cpp file because best practice is not to include cpp files, and then include that file into the header.
Whatever you do at the time the compiler sees the template function call it must have already seen the definition of the template.
Banfa
Practically a Master Poster
600 posts since Mar 2010
Reputation Points: 486
Solved Threads: 92