Ambiguous overloaded log function call in Visual C++ .NET

  • Context: C/C++ 
  • Thread starter Thread starter Math Is Hard
  • Start date Start date
  • Tags Tags
    Error
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
4 replies · 3K views
Staff Emeritus
Science Advisor
Gold Member
Messages
4,663
Reaction score
36
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!
 
Physics news on Phys.org
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 )
 
Last edited:
Thanks, dduardo. I was breaking out in a mild panic!
Is what you did there the same as using static_cast<double>?
 
Yeah, you can write it either way. The parentheses is just a shorthand.
 
Last edited: