operator/
除算演算子を追加。
先ほどと同じようにFriction.hにある分数のテンプレートに下記を追加。
TFriction<T> operator/( TFriction<T> t ) { this->Exec(); t.Exec(); TFriction<T> temp( this->m_numerator*t.GetDenominator(), // 分子 this->m_denominator*t.GetNumerator() ); // 分母 temp = temp.reduction(); return temp; }
main.cpp
// main.cpp #include "Friction.h" int main() { TFriction<int> a( 3, 5 ), b( 4, -4 ), c; c = a / b; c.Disp(); // c = -3/5 c = b / a; c.Disp(); // c = -5/3 a.SetNumerator(2); a.SetDenominator(9); b.SetNumerator(14); b.SetDenominator(3); c = a / b; c.Disp(); // c = 1/21 return 0; }