I don't think you can. You could include the entire template function body in the header; although this technically is wrong, I have heard that compilers will allow it because template must be defined wherever they are used. I know for certain that VC++ 2008 allows it...
i mean if i can put something like a normal function prototype near the start of the program and define it after I use it in main within the same file?
@helios: You can actually split definition and implementation into two files, but it ain't pretty, and as far as I understand it is also not recommended:
1 2 3 4 5 6 7 8 9 10 11 12 13
// Filename: Point.h
template<typename T>
class Point
{
public:
T getX();
T getY();
private:
T myX;
T myY;
}
#include "Point.tmpl"
1 2 3 4 5 6
//filename: Point.tmpl
template<typename T>
T Point::getX() { return myX; }
template<typename T>
T Point::getY() { return myY; }
I'm sure the compiler will give at least two flying ***** that the definition is in a different physical file but included with the declaration.
The point of spreading a program across several files is, aside from organization, not having to recompile the entire code every time a change is made to any part of it.