C/C++ Help Error in MSVC++ .NET version

  • Thread starter Thread starter Math Is Hard
  • Start date Start date
  • Tags Tags
    Error
AI Thread Summary
The discussion centers on an issue with using Visual C++ .NET, specifically an error encountered when executing a line of code that calculates the logarithm of a number. The original code, which worked in MSVC++ v6, produced an "ambiguous call to overloaded function" error in .NET due to the overloaded nature of the log function in the cmath header. The solution provided involves typecasting the variable 'num' to double before passing it to the log function, which resolves the ambiguity. It is noted that using a simple cast like (double)num is equivalent to using static_cast<double>. The conversation highlights the importance of understanding function overloading and typecasting in C++.
Math Is Hard
Staff Emeritus
Science Advisor
Gold Member
Messages
4,650
Reaction score
39
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!
 
Technology 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:
oh, ok... thanks!
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top