954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Error Problem

Hey all I have a bit of a problem, I need a little help fixing this little error problem. The Error is "error C2668: 'sqrt' : ambiguous call to overloaded function" it is on this line of code:

void myint::square()
{   
    // Output square root

	cout << "The square root of " << num << " is " << sqrt(num) << endl;
}


can someone help me?

WesFox13
Light Poster
27 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

what is num ? It needs to be either double or float ( link ). If it isn't then typecast it to one of these.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

I think you need to include cmath and or compile with -lm

monkey_king
Junior Poster
160 posts since Aug 2008
Reputation Points: 70
Solved Threads: 9
 

sqrt() requires a double, float, or long double as a parameter. Judging by your variable name, you're attempting to pass an int to sqrt(). Try using static_cast to convert it to a double like so:

cout << "The square root of " << num << " is " << sqrt(static_cast<double>(num)) << endl;
Evan M
Light Poster
42 posts since Sep 2007
Reputation Points: 11
Solved Threads: 5
 

Thanks Evan, your solution worked.

WesFox13
Light Poster
27 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You