PDA

View Full Version : Help! Error in MSVC++ .NET version


Math Is Hard
Feb3-05, 11:53 AM
Is anyone here using Visual C++ .NET?
I have a line of code that works fine in MSVC++ v6, but I am getting an error in MSVC++ .NET. :mad: :cry: :cry:

Here's the line:

expo = (log(num))/(log(10));

and the error message I get:

error C2668: 'log': ambiguous call to overloaded function

expo is a type int variable. so is num.
I am using the cmath header:
#include <cmath>

Thanks for any help!

dduardo
Feb3-05, 12:11 PM
It should be:

expo = log((double)num)/log(10.) ;

And you'll get a warning if expo is not a double. num can stay int since i've typecasted it.

The log function in cmath is defined as:

double log( double )
long double log( long double )
float log( float )

Math Is Hard
Feb3-05, 12:17 PM
Thanks, dduardo. I was breaking out in a mild panic!!
Is what you did there the same as using static_cast<double>?

dduardo
Feb3-05, 12:21 PM
Yeah, you can write it either way. The parentheses is just a shorthand.

Math Is Hard
Feb3-05, 12:22 PM
oh, ok... thanks!