I am trying to organize files while using function templates as shown in the following:
template <class T>
T max(T a, T b)
{
return a > b ? a : b;
}
int main()
{
cout << "max(10, 15) = " << max(10, 15) << endl;
retun 0;
}
I simply put the implementation of "max(T a, T b)" in a templateMaxFun.cpp and the following in templateMaxFun.h file:
template <class T>
T max(T a, T b);
Then, I put #include "templateMaxFun.h" in the main.cpp. However, the compiler is complaining: "undefined reference to `int max(int, int)".
My question is: what is the correct way to put a template function prototype in the .h file? I am guessing my problem might be here.
Thanks for your help.