   About C++ and template
  I used a template like this:template <class T>T test(int n){    if (n < 0)    {   cout << "Error!" << endl;   //Now,I want exit this function,not program.   //So I use "return" not "exit"   //But how to return with a value, I don't know the "T" type.    }    ......    ......}   
Quote:Original post by hanckjtI used a template like this:template <class T>T test(int n){    if (n < 0)    {   cout << "Error!" << endl;   //Now,I want exit this function,not program.   //So I use "return" not "exit"   //But how to return with a value, I don't know the "T" type.    }    ......    ......}template <class RETVAL> RETVAL test (int n){RETVAL a;return a;};  Consider also using an assertion if n begin less than 0 is a logic flaw, or possibly an exception, should the error require one.template <class T>T test(int n){  assert(n >= 0);  // code}template <class T>T test(int n){   if (n < 0)   { throw ExceptionClass(" N<0!");   }   //code} [Edited by - rip-off on May 28, 2006 2:58:14 PM];  I like the try....throw....catch way.OK,thanks everybody who helped me.   