0
マップに多項式を含むPoly
クラスがあります。 +=
演算子をオーバーロードして、同じ指数関数を乗算器に加算する方法はありますか?C++マップを使用してクラスの+ =演算子をオーバーロードする方法?
例:
4x²+2x+7
が(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) {
// ???
}
の可能な複製を、[演算子のオーバーロードのための基本的なルールやイディオムは何ですか?]( https://stackoverflow.com/questions/4421706/what-are-the-basic-rules-and-idioms-for-operator-overloading) – user0042
ベクトで乗数を保持するBtw rはメモリとパフォーマンスによって大幅に効率的になります。理論的には、より多くのメモリを使用することもできますが、それはほとんどあり得ません。 – Slava
あなたのプログラムを再構築することをお勧めします。係数と指数を持つ 'Term'クラスを作成します。 '多項式'は 'Term'のコンテナです。 –