C ++では、integer
クラスを実装しoperator ^
、べき関数になるようにオーバーロードしました。
integer integer::operator^ (const integer& rhs){
return integer(pow(this->.i, rhs.i));
}
これは、2つのオペランドに対して正しく機能しています。
integer i1, i2, i3 ;
i4 = i1 ^ i2 ^ i3;
i4
結合法則には右から左が必要なため、の値は数学的に間違っています。どうすればこの問題を解決できますか?結合性を変更するにはどうすればよいですか?
私は合理的な答えを得て、私は学びます:
-We can't change associativity or priority of an operator.
-Good is Not to overload operators to do something conceptually different to
the built-in versions
-Even compiler can't support; it hard to implement!