--------------------Configuration: zy1 - Win32 Debug--------------------
Compiling...
1.cpp
D:\VC++6.0\Microsoft Visual Studio\MyProjects\zy1\1.cpp(47) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
執行 cl.exe 時出錯.
1.obj - 1 error(s), 0 warning(s)
/*1.已知一個有理數類zrf_Ratio,包含私有數據成員:分子num和分母den, 以及公有函數成員 friend ostream& operator<<(ostream& ostr, const zrf_Ratio& r) { return ostr << r.num << "/" << r.den;} 請補充該類的構造函數,並實現如下的操作符重載形式: friend zrf_Ratio operator-(const zrf_Ratio&); friend zrf_Ratio operator+(const zrf_Ratio&, const zrf_Ratio&); friend zrf_Ratio operator-(const zrf_Ratio&, const zrf_Ratio&); friend zrf_Ratio operator*(const zrf_Ratio&, const zrf_Ratio&); friend zrf_Ratio operator/(const zrf_Ratio&, const zrf_Ratio&);*/
#include
using namespace std;
int f1()
{ int m,n,t;
cout<<"請輸入兩個數:";
cin>>m>>n;
while(n!=0)
{ t=m%n; m=n; n=t; }
return m;
}
class zrf_Ratio
{
public:
friend ostream& operator<<(ostream& ostr, const zrf_Ratio& r)
{ return ostr << r.num << "/" << r.den;}
friend zrf_Ratio operator-(const zrf_Ratio& r0 )
{return zrf_Ratio(-r0.num,r0.den);}
friend zrf_Ratio operator+(const zrf_Ratio& r1, const zrf_Ratio& r2)
{ int a=f1(r1.den,r2.den); return zrf_Ratio((r1.num*r2.den+r2.num*r1.den)/d,r1.den*r2.den/d); }
friend zrf_Ratio operator-(const zrf_Ratio& r1, const zrf_Ratio& r2)
{ int a=f1(r1.den,r2.den); return zrf_Ratio((r1.num*r2.den-r2.num*r1.den)/d,r1.den*r2.den/d); }
friend zrf_Ratio operator*(const zrf_Ratio& r1, const zrf_Ratio& r2)
{ int a=f1(r1.den,r2.den); while(a!=1) { r1.num*r2.num/=d; r1.den*r2.den/=d; d=f1(r1.num*r2.num,r1.den*r2.den); } return zrf_Ratio(r1.num*r2.num,r1.den*r2.den); }
friend zrf_Ratio operator/(const zrf_Ratio& r1, const zrf_Ratio& r2)
{return r1*zrf_Ratio(r2.num,r2.den);}
private:
int num,den;
};
int mian()
{
zrf_Ratio m(3,7);
zrf_Ratio n(4,9);
p(-a);
p(a+b);
p(a-b);
p(a*b);
p(a/b);
return 0; }
就是這個題目,這代碼肯定有好多錯誤,希望前輩可以耐心指教,謝謝