I am trying to run an example of Function Overloading in C++. But Its showing me following error
function.cpp(21): error C2084: function 'double abs(double)' already has a body
include\math.h(495) : see previous definition of 'abs'
function.cpp(26): error C2084: function 'long abs(long)' already has a body
include\stdlib.h(467) : see previous definition of 'abs'
Program
#include<iostream>
using namespace std;
int abs(int i);
double abs(double d);
long abs(long l);
int main()
{
cout << abs(-10);
cout << abs(-20.2);
cout << abs(-30L);
return 0;
}
int abs(int i)
{
cout << "Using int \n";
return i<0 ? -i:i;
}
double abs(double d)
{
cout << "Using Double \n";
return d<0.0 ?-d:d;
}
long abs(long l)
{
cout << "Using Long\n";
return l<0?-l:l;
}
I have copied the same code as given in book C++ Complete Reference , Fourth Edition by Herbert Schildt