#include <iostream>
using namespace std;
class F{
int a; //分子
int b; //分母
public:
F(int a=0, int b=0):a(a),b(b)
{
}
void show()
{
cout << a << '/' << b << endl;
}
F operator*(const F& o)const
{
return F(a*o.a, b*o.b);
}
friend F operator/(const F& f1, const F&f2);
};
F operator/(const F& f1, const F& f2)
{
return F(f1.a*f2.b, f1.b*f2.a);
}
int main()
{
F obj1(3,5);
F obj2(5,8);
F obj3, obj4, obj5;
/* obj3 = obj1.operator*(obj2);
obj3.show();
obj4 = obj1 * obj2;
obj4.show();*/
obj5 = obj1 / obj2;
obj5.show();
return 0;
}
友员函数 operator
最新推荐文章于 2024-06-19 22:13:34 发布