math??

I'm using Microsoft Visual Studio 2008 and I need math like sqrt() and pow() but #included <math> is not working for me.

*I'm using namespace std*
Try #include <cmath>
no good its giving me this errors

Error 1 error C2668: 'pow' : ambiguous call to overloaded function u:\visual studio 2008\projects\grid\grid\grid.cpp 250 grid

Error 2 error C2668: 'sqrt' : ambiguous call to overloaded function u:\visual studio 2008\projects\grid\grid\grid.cpp 250 grid
closed account (z05DSL3A)
That would be due to what you are passing into it. Post your code.
This is because they have several overloads but not all the combinations, try to cast all the arguments you are passing to double
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
	int alpha;
	int beta;
	int a;
	int b;

	int length;
	int height;
	int Long;
	int High;
	int hop;

       double radius;


do{
	a = High + 1 + h;
	i = 0;
	do{
		b = Long + 1 + i;
		alpha = pow (a,2);
		beta = pow (b,2);
		radius = sqrt(alpha + beta);
		if ( grid[High][Long] == s && grid[a][b] == s)
		{
			cout << "(" << a << "," << b << "), ";
		}
		i = i + 1;
	}while (radius <= hop);
	h = h + 1;
}while (radius <= hop);
Bazzy's already given the answer. Try pow((double)a, 2), etc.
well the cleared up the sqrt problem but not the pow problem
are you including
 
using namespace std;

it is apart of the standard namepsace,
or just enter
1
2
std::pow(a,2);
std::sqrt(alpha+beta);
ya I'm using/includeing namespace std
Here are listed all the pow overloads: http://www.cplusplus.com/reference/clibrary/cmath/pow/

You can cast your arguments in a way that the function call is unambiguous, a way of achieving this is casting just the exponent to double ( so you will call double pow ( double base, double exponent ) ).
This can be done in your case by modifying the numeric literal:
pow( a, 2.0 )
closed account (z05DSL3A)
alpha = pow (a,2); the compiler does not know how to treat the parameters. Casting a to double is only part of the solution, it still needs to know what 2 is, change it to 2.0

Edit:
late again.
Last edited on
thanks that worked!
Casting a to double is only part of the solution

I was targetting this particular overload:

double pow( double base, int exponent );

Don't know why it didn't work.
closed account (z05DSL3A)
I was targetting this particular overload:

double pow( double base, int exponent );

Don't know why it didn't work.


because in the case of pow (a,2);, the compiler does not know how to treat the literal '2', it can treat it as an int or a double because there are overload for both. So you would have to cast it to int or include the .0 to remove the ambiguity.
Topic archived. No new replies allowed.