can't use the "pow" function?

For some reason when I call

cout<<pow (2,some_variable_defined_by_user));

I get the following error:

error C2668: 'pow' : ambiguous call to overloaded function

anyone know why this is and have a solution? I'm stuck :(

It's the "pow(2,some_variable_defined_by_user)". It means that there are other versions of the function that take different arguments or different numbers of arguments, and you haven't provided enough information for it to figure out which one you wanted.

1
2
3
4
5
6
pow(int a, int b, int c = 0);
//and
pow(int a, int b, char c = "", int d = 0);
//defined...wherever

pow(x,y); //<-- would return ambigous call because compiler can't tell which function you want  


TAKEN FROM http://www.cplusplus.com/forum/beginner/3165/

the solution would be to make:

cout<<pow (2,some_variable_defined_by_user,0);
Last edited on
The pow() function takes a double, float or an int as the exponent, and a double or a float as the base. You need to tell the compiler which kind you want it to use. To do this, typecast your constant values:
 
pow((double)2, X);


EDIT: Remember, if you give it a type that it needs to implicitly typecast, such as (int) for the base, then you will still get an error because it can be cast to multiple types.
Last edited on
Topic archived. No new replies allowed.