I have started to learn templates and I am having a few issues with compilation and linking errors. After a little research with Google, I found that I should do one of two things: either include a *.cpp file or place the function definitions in my header file for the class in which I am trying to define. I also read that including a *.cpp file is a really bad practice. Also, is it bad to place the definitions in a header file, should do this, and the bigger question, why? I am hoping that someone with more experience and background can look at this and tell me the hows, whys and so forth. I would also like to see a simple example if at all possible. Thank you in advance for any and all help as well as for your time.
The stl classes are declared and implemented in a single header file, so this might be a good example to follow.
One example: https://www.sgi.com/tech/stl/string
When dealing with templates, both the definitions and the implementations must be in the same compilation unit.
I found that I should do one of two things: either include a *.cpp file or place the function definitions in my header file for the class in which I am trying to define.
Normally including source files in headers is a bad practice but it is acceptable when dealing with templates. However many people would recommend changing the file extension to something other than .cpp. For example use .inc instead of .cpp.
Also, is it bad to place the definitions in a header file, should do this, and the bigger question, why?
When dealing with template classes it is quite normal to end up with a header only "library". For the why please read the first paragraph.