I am writing a polynomial class but the code I have written to overload the ostream operator<< goes into a infinite loop for the first term. I tried to step through but Visual Studio 2010 goes into linker(?) code instead of only stepping through my code. (How to change the setting would help (: ) Anyway, it worked fine when I left it simple to just iterating down without much formatting. But this formatted polynomial I've made causes the infinite loop.

size = size of the coefficient array where the position in the array is the power

``````friend ostream &operator<<(ostream &Out, const Poly &rhs)
{
for(int i = (rhs.size - 1); i > 0; i--)
{
if(i = rhs.size - 1)
{
if(rhs.coeff[i] > 0)
Out << rhs.coeff[i] << "X^" << i << " ";
else
if(rhs.coeff[i] < 0)
Out << "-" << rhs.coeff[i] << "X^" << i;
}
else if(rhs.coeff[i] > 0)
Out << " + " << rhs.coeff[i] << "X^" << i;
else if(rhs.coeff[i] < 0)
Out << " - " << (rhs.coeff[i] * -1) << "X^" << i;
}
if(rhs.coeff[0] > 0)
Out << " + " << rhs.coeff[0];
else if(rhs.coeff[0] < 0)
Out << " - " << (rhs.coeff[0] * -1);

return Out;
}``````

The problem is here -> `if(i = rhs.size - 1)` . It should be -> `if(i == rhs.size - 1)`
The problem is here -> `if(i = rhs.size - 1)` . It should be -> `if(i == rhs.size - 1)`