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?

Recommended Answers

All 4 Replies

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

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

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;
commented: THis really Helped, thank you +1

Thanks Evan, your solution worked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.