Template problem ...

Hi all,
Need your help. I am doing a simple template program , getting some error ... here is the code

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include<iostream>
#include<string>
#include <sstream>
using namespace std;
class Base_class
{
public:
Base_class(){ };
~Base_class(){ };
template <class T>
static int fun(T decimal_value,string& check)
{
ostringstream ostr;
ostr<<decimal_value<<endl;
string str=ostr.str();
check=str;
return 0;
}
};
int main()
{
try
{
string check;
int a=7777;
Base_class ::fun(a,check);
cout<<check<<endl;
double b=7777.9755;
Base_class::fun(b,check);
cout<<check<<endl;
char c[]="AMARTYA";
Base_class::fun(c,check);
cout<<check<<endl;
}
catch(...)
{
cout<<"Function Cutil::failed"<<endl;
}
return 0;
}

This code works fine ....
But i want the Definition of the function not in the main class , i want to put it outside function ......
If i do that ..... It is giving error .....
Please provide some solution(s)...

You didn't post the code that doesn't work, but I guess that you want to define the method template in a separate file rather than in the definition of the class, as one often does for normal class methods.
Short answer; you can't.

There is, no doubt, a better explanation in a text book somewhere, but here goes...
Templates are not like normal code; you cannot define them where ever you like. When the compiler sees your call to

int a;
Base_class::fun(a,check);

here is no method with signature

fun(int, string&);

so it has to create one from the template you supplied. This means that the compiler has to be able to see the both the template (so it knows how to build the function) and the call (so it knows what types to build the function with) at the same time. So the template and the code calling the method must be in the same compilation unit.
You don't have to have the method template defined inline, but you must have it defined where the class is defined.