For instance, assume that, after an addition operation, the actual result is:
P(x) = 1.2 + 3.4x - 6.0x^2 + 5.9x^4
But it is stored as:
[1.2; 3.4; -6.2; 0.0; 5.9; 0.0; 0.0]
I want to remove the last two zero terms.
My code is this:
template<class T> // "T" is "long double" for this instance
void Polynomial<T>::CleanZeroCoefficients()
{
for (std::vector<T>::const_iterator it=m_Coefficients.end(); it!=m_Coefficients.begin(); it--)
{
if (*it == static_cast<T>(0)) // Exception given at this line
{
// Definition: "std::vector<T> m_Coefficients;"
m_Coefficients.erase(it);
}
else
{
break;
}
}
}
This code gives this exception:
What is wrong with this code, and how do I fix it?
Thanks.
(IDE: Visual Studio 2010)