6 years, 11 months ago.

math.h function pow error

Hello,

So I've tried to use the function pow in my program and it gives me the following error:

More than one instance of overloaded function "pow" matches the argument list "double a = pow(2,3);" Error 308

and the line of code in question is as follows:

double a = pow(2,3);

Does anyone know why I'm getting this error? I get the same error when I use other math functions like log too.

Thanks. :)

1 Answer

6 years, 11 months ago.

Hello Manisha,

It means that more overloaded versions of pow() function match the argument list of two numbers you are trying to pass it. So the compiler is not able to make the decision which one to use. For the sake of simplicity, let's assume there are the following two functions available:

double pow(int, int);
double pow(unsigned int, unsigned int);

and in your code, you call the the pow function passing it literals 2 and 3 as follows:

double a = pow(2, 3);

SInce for the compiler it's equally OK to use pow(int, int) as pow(unsigned int, unsigned int) it is not able to guess what was your intention. In order to help it conclude make the code unambiguous.
For example, you can pass more specific literals:

double a = pow(2u, 3u);  // Here you pass unsigned integers so only the second version fits

or define the arguments clearly before calling the function:

int x = 2;
int y = 3;

double a = pow(x, y);  // Here you pass integers so only the first version fits