Being new to C++, I was wondering what the best practices are regarding generic functions. I'm trying to implement a global function that takes as arguments a vector of generic data points, a function that maps one such data point to a different generic type as well as a generic pointer to return the mapped data point:
template <class Parameter_T, class Data_T, class CalculateParameterF>
void example(vector<Data_T> data,
CalculateParameterF calculateParameters,
Parameter_T& bestFittingParameters);
Now to my question: If I put the above declaration in a header file and its implementation in a .cpp
file, the code won't compile. If I understand correctly, the compiler doesn't understand how it should compile the generic function exactly. In order to give it some hints, I can either leave the implementation body in the header file or add a second declaration filling in the specific types that I want to use it with.
However, both of these solutions seem to be a bit ugly. Are these really the only solutions or am I missing something? If no, what solution should I prefer and why?