I have Poly
class that contains a polynomial in a map. How can I overload the +=
operator for it so that it adds together multipliers with the same exponential?
example:
4x²+2x+7
is contained as (2, 4), (1, 2), (0, 7)
class Poly {
typedef std::map<int, int> Values;
Values m_values;
public:
typedef Values::const_reverse_iterator const_iterator;
typedef Values::reverse_iterator iterator;
int operator[](int exp) const;
Poly& operator+=(Poly const& b);
Poly& operator-=(Poly const& b);
};
Poly& Poly::operator+=(Poly const& b) {
// ???
}