I am using Visual C++ and when I compile the following code there are no errors or warnings. However, when I compile with g++ I get 3 errors and 1 warning.
Here is the part of the code that generated the errors.
----------------------------------------------------------------------------------------------------------------
[CODE=cpp]int divsum(int x, vector<int> y) //returns the sum of the PROPER divisors
{
int t;
double sum=1;
int L=y.size();
for(t=0; t<L; t++) //go through each element of the list of generated primes
{
int e=1;
double psum=1;
if(x%y[t]==0)//test for divisibility
{
while(fmod(x,po w(y[t],e))==0) //sum of p^e where p^e divides y
{
psum=(int) psum+pow(y[t],e);
e++;
}
sum=sum*psum; //formula for divisor sum
}
}
int rsum; rsum= (int)sum;
return rsum-x;
}[/CODE]
-------------------------------------------------------------------------------------------------------------
The error messages all read something similar to: "divisorsum.cpp :73: error: call of overloaded âpow(int&, int&)â is ambiguous"
What is the mistake, and how can I avoid making it in the future?
Here is the part of the code that generated the errors.
----------------------------------------------------------------------------------------------------------------
[CODE=cpp]int divsum(int x, vector<int> y) //returns the sum of the PROPER divisors
{
int t;
double sum=1;
int L=y.size();
for(t=0; t<L; t++) //go through each element of the list of generated primes
{
int e=1;
double psum=1;
if(x%y[t]==0)//test for divisibility
{
while(fmod(x,po w(y[t],e))==0) //sum of p^e where p^e divides y
{
psum=(int) psum+pow(y[t],e);
e++;
}
sum=sum*psum; //formula for divisor sum
}
}
int rsum; rsum= (int)sum;
return rsum-x;
}[/CODE]
-------------------------------------------------------------------------------------------------------------
The error messages all read something similar to: "divisorsum.cpp :73: error: call of overloaded âpow(int&, int&)â is ambiguous"
What is the mistake, and how can I avoid making it in the future?
Comment