Help Error in MSVC++ .NET version

  • Context: C/C++ 
  • Thread starter Thread starter Math Is Hard
  • Start date Start date
  • Tags Tags
    Error
Click For Summary

Discussion Overview

The discussion revolves around an error encountered in Visual C++ .NET when using the logarithm function from the cmath header. Participants explore the differences in behavior between MSVC++ versions and how to resolve the ambiguity in function calls related to type handling.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Homework-related

Main Points Raised

  • One participant reports an error message regarding an ambiguous call to the overloaded function 'log' when transitioning from MSVC++ v6 to MSVC++ .NET.
  • Another participant suggests typecasting the variable 'num' to double to resolve the ambiguity in the log function call.
  • A question is raised about whether the suggested typecasting is equivalent to using static_cast, indicating a consideration of different casting methods.
  • Clarification is provided that both typecasting methods (parentheses and static_cast) achieve the same result.

Areas of Agreement / Disagreement

Participants generally agree on the need for typecasting to resolve the ambiguity in the log function, but there is no explicit consensus on the preferred method of typecasting.

Contextual Notes

The discussion does not address potential limitations or assumptions regarding the types of variables or the specific context in which the error occurs.

Who May Find This Useful

Programmers using Visual C++ .NET, particularly those transitioning from earlier versions or dealing with function overloading and typecasting issues.

Math Is Hard
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!
 
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!
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
Replies
12
Views
2K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 57 ·
2
Replies
57
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
13K
Replies
17
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K