ambiguity error caused by function overload?
Hi there,
I just finished this and had a question.
I was asked to "create a void function called round() that rounds the value of its double argument to the nearest whole value. Have round() use a reference parameter and return the rounded result in this parameter."
Here's my code (which works fine now):
Code:
// Rounding Program
#include <iostream>
#include <cmath>
using namespace std;
void rounD (double &val); // function prototype
int main()
{
double input;
cout << "Enter a value: ";
cin >> input;
rounD (input);
cout << "\n\nRounded value is: " << input;
cin.ignore();
cin.get();
return 0;
}
/*Functions*/
void rounD (double &val)
{
double intPart;
double *pintPart;
pintPart = &intPart;
double fracPart = modf(val, pintPart);
/* couts used in debugging - really helped!*/
cout << "Val: " << val << "\n";
cout << "fracPart: " << fracPart << "\n";
cout << "intPart: " << intPart << "\n";
if (fracPart >= 0.5) val = (intPart + 1);
else val = intPart;
}
It works fine now but at first I kept getting an ambiguity error when I called the function. I knew this happens when you overload a function and feed it an ambiguous value. But I only had one function! I figured, then, that there must be another function in <cmath> with the same name... so I just changed the name of my function slightly and it compiled with no problems. After that I searched the <cmath> header but there doesn't seem to be a round() function in there at all!
So my question is: if my ambiguity error was caused by function overload, where did this other mysterious, invisible, trouble-making function come from? Or, if the error was not caused by function overload, what did cause it?
Guess that's a bit of a long way to ask a short question. :D Sorry for that. Any comments would be really appreciated, though.
Thanks
Ps. I'm using Dev-C++ on Windows XP