Function templates and namespaces
Posted on 2003-12-04
Ok, I have 3 files: compare.h, compare.cpp, and main.cpp
I am trying to write a function template to compare two numbers and return the largest. I want to put the template prototype in compare.h, template definition in compare.cpp, and the code in main.cpp
My book explains how to do it with functions, but not with function templates. K, here is the code as I wrote it.
template<class T> T max(const T num1, const T num2);
template<class T> T compare::max(const T num1, const T num2)
return (num1 > num2 ? num1 : num2);
std::cout << max(5.0, 7.0);
I recieve "unresolved externals .." when trying to compile. Also, in by book, it says "Because we are using class templates you will need to prefix each of the template definitions with keyword 'export'. The code will the be fully compatible with ANSI/ISO standard .."
Question is, where exactly do I put this 'export' keyword?