MTSL/h/Faction.h
2022-09-28 20:27:28 +08:00

28 lines
556 B
C++

//
// Created by dongl on 22-9-27.
//
#ifndef MSTL_FACTION_H
#define MSTL_FACTION_H
#endif //MSTL_FACTION_H
// 转换函数 重载
class Faction{
public:
explicit Faction(int num, int den = 1):m_numerator(num),m_denominator(den){}
// 这种东西 转化为 别一种
operator double() const{
return (double) m_numerator / m_denominator;
}
// 别种东西 转化为这一种
double operator+(const Faction& f){
return Faction(f);
}
private:
int m_numerator; // 分子
int m_denominator; // 分母
};