How bad at programming am I? Am I a horrible person for this?
//templates.cpp
template <typename TYPE> void some_func(int arg1, ...)
{
//do stuff
}
Then:
//templates.h
#ifndef TEMPLATES_H_INCLUDED
#define TEMPLATES_H_INCLUDED
#include "templates.cpp"
template <typename TYPE> void some_func(int arg1, ...);
#endif
Finally:
//main.cpp
#include "templates.h"
int main ...
some_func<int>(5);
std::fprintf(stderr, "ZOMG IT WORKT!\n!\n!\n!");
It works fine for me. It seems to solve the endless question a lot of us n00bs have about how to correctly separate .cpp and .h files for templates and then include them without compiler errors.
The line #include "templates.cpp" in the templates.h file is basically equivalent to including your declarations and source code all in one file. But this method nicely separates them, which is what we all seem to be looking for.
.ipp, others may use.inl.