Well, to start off, I am attempting to do one of the programming projects in Problem Solving with C++ by Walter Savitch. The program asks me to overload the "abs" function using the "long", "int", "float", and "double" types, which, I try to do here:
Code:
#include<iostream>
#include<cstdlib>
using namespace std;
int abs(int i); // Function Definitions
double abs(double d);
float abs(float f);
long abs(long l);
int main()
{
int i = 1;
double d = 2.0;
float f = 3.0;
long l = -4;
cout << "Overloading Functions\n";
cout << "Int: " << abs(i) << endl;
cout << "Float: " << abs(d) << endl;
cout << "Double: " << abs(f) << endl;
cout << "Long: " << abs(l) << endl;
system("PAUSE");
return 0;
}
With the errors being as follows:
In function `int main()':
note :5 candidates are: int abs(int)
20 call of overloaded `abs(long int&)' is ambiguous
note double abs(double)
note float abs(float)
note long int abs(long int)
note long long int __gnu_cxx::abs(long long int)
note long int std::abs(long int)
Using latest beta of DevC++...not sure if I am doing something blatantly obvious as far as overloading goes, or maybe I just misunderstood the concept...but from the tutorials and information I have read...it looks right, but alas, I am not sure what's wrong. Any help would be greatly appreciated...my goal is to have a good understanding of c++.