筱羅卜
2015-06-09 05:34
采纳率: 100%
浏览 1.7k

编译时出现这样的错误,求大神指点解决方法

程序如下:
#include
using namespace std;
class zrf_Ratio;
zrf_Ratio operator+(const zrf_Ratio& r1, const zrf_Ratio& r2);
zrf_Ratio operator-(const zrf_Ratio&, const zrf_Ratio&);
zrf_Ratio operator*(const zrf_Ratio&, const zrf_Ratio&);
zrf_Ratio operator/(const zrf_Ratio&, const zrf_Ratio&);

class zrf_Ratio
{
public:
zrf_Ratio(){}
zrf_Ratio(int r1,int r2):num(r1),den(r2){}
zrf_Ratio f1(zrf_Ratio& z)
{
int r,m=z.num,n=z.den;
while(r=z.num%z.den)
{
z.num=z.den;
z.den=r;
}
r=z.den;
z.num=m/r;
z.den=n/r;
return z;
}
friend ostream& operator<<(ostream& ostr, const zrf_Ratio& r)
{ return ostr << r.num << "/" << r.den;}

zrf_Ratio operator-(const zrf_Ratio& r1)
{return f1(zrf_Ratio(num*r1.den-r1.num*den,den*r1.den));}

friend zrf_Ratio operator+(const zrf_Ratio& r1, const zrf_Ratio& r2)
{
    zrf_Ratio a;
    return a.f1(zrf_Ratio(r1.num*r2.den+r2.num*r1.den,r1.den*r2.den));
}

friend zrf_Ratio operator-(const zrf_Ratio& r1, const zrf_Ratio& r2)
{
    zrf_Ratio a;
    return a.f1(zrf_Ratio(r1.num*r2.den-r2.num*r1.den,r1.den*r2.den));
}

friend zrf_Ratio operator*(const zrf_Ratio& r1, const zrf_Ratio& r2)
{
    zrf_Ratio a;
    return a.f1(zrf_Ratio(r1.num*r2.num,r1.den*r2.den));
}

friend zrf_Ratio operator/(const zrf_Ratio& r1, const zrf_Ratio& r2)
{
    zrf_Ratio a;
    return a.f1(zrf_Ratio(r1.num*r2.den,r1.den*r2.num));
}

private:
int num,den;
};
int mian()
{
zrf_Ratio x(3,7),y(4,9),z;
z=x.operator-(y);
cout<<"x-y="<<z<<endl;
z=x+y;
cout<<"x+y="<<z<<endl;
z=x-y;
cout<<"x-y="<<z<<endl;
z=x*y;
cout<<"x*y="<<z<<endl;
z=x/y;
cout<<"x/y="<<z<<endl;
return 0;
}
显示错误如下:
Deleting intermediate files and output files for project '2 - Win32 Debug'.
--------------------Configuration: 2 - Win32 Debug--------------------
Compiling...
2.cpp
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/2.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.

2.exe - 1 error(s), 0 warning(s)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • blownewbee 2015-06-09 05:39
    已采纳

    main拼写错了

    点赞 评论
  • fcxxxer 2015-06-10 12:35

    main拼写错误。。。

    点赞 评论

相关推荐 更多相似问题