C++ template function generic

Description

C++ template function generic

#include <iostream>
using namespace std;
template <class T>
void showabs(T number)
{
   if (number < 0)
      number = -number;//from  w w w. j a  v  a 2  s .c om
   cout << "The absolute value of the number is "
   << number << endl;
   return;
}
int main()
{
   int num1 = -4;
   float num2 = -4.23f;
   double num3 = -4.23456;
   showabs(num1);
   showabs(num2);
   showabs(num3);
   return 0;
}



PreviousNext

Related