Error in pow function

Hey guys I know the pow function takes 2 doubles but I static casted it to an int and I still get the error more than one instance matches the arguement list.
What am I doing wrong? Error is on line 22.

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
31
32
33
34
//Binary to Decimal

#include <iostream>
#include <cmath>
using namespace std;

int bin2dec(int num); //converts binary number to a decimal number
int bin2dec(int num , int pl); //overloaded function 

int bin2dec(int num)
{
	return bin2dec(num,0);
}

int bin2dec(int num , int pl)
{
	if(num==0)
		return 0;
	else
		return num % 10 * int(pow(2,pl)) * bin2dec(num/10 , pl+1);
}

int main()
{
	char again = 'Y';
	do{
		cout << "Enter a number in binary (1's and 0's) to see the decimal equivalent: ";
		int bin;
		cin >> bin;
		cout << "The decimal equivalent of " << bin << " is: " << bin2dec(bin);
		cout << "Another?(Y/N) : ";
		cin >> again;
	}while(toupper(again)=='Y');
}//endmain 
Before C++11 there was no version of std::pow taking an integer as first argument so it doesn't know if it should use the one taking a float, the one taking a double or the one taking a long double as first argument.

To solve this you have two options.

1. Cast the first argument to one of the floating point types.
2. Compile the code in C++11 mode. If your compiler is too old you'll have to upgrade first.
Last edited on
I have visual studio 2010. I would rather just keep it. Do I need to change my parameter to a double?
Yeah, I think you just need to change the first argument to a double. Try: pow(2.0,pl)
Ok do I need to change it in my prototypes and function arguments also?
That fixed it but for some reason I keep getting zero as my output.
Topic archived. No new replies allowed.