I am learning overloading an inline function.
In testing this code I can't compile with the following errors I can't understand as to what's wrong.
I tested it with only 1 inline function and works but a second breaks it. Can you please share some guidance:
Thank you for your help, Sergio
Compiler errors:
- abs exception specification does not match previous declaration line 13
- function long abs (const long) throw() already has body line 13
- abs redefinition; different exception specification line 19
- abs error in function definition or declaration; function not called line 30
- abs error in function definition or declaration; function not called line 32
#include "pch.h"
#include <iostream>
using namespace std;
// Overload abs() three ways
inline int abs(int n)
{
cout << "In integer abs() \n";
return((n < 0) ? -n : n);
}
inline long abs(long n)
{
cout << "In long abs() \n";
return((n < 0) ? -n : n);
}
inline double abs(double n) {
cout << "In double abs() \n";
return ((n < 0 ? -n : n));
}
int main()
{
cout << "Absolute value of -10 Is ";
cout << abs(-10) << "\n";
cout << "Absolute value of -10L Is ";
cout << abs(-10L) << "\n";
cout << "Absolute value of -10.01 Is ";
cout << abs(-10.01) << "\n";
}