一段简单的c++运算符重载的代码 各位帮忙看看错在哪里 我是没弄懂= =~新手 勿拍

#include<iostream.h>classcircle{private:doubleradius;public:circle();circle(doublex);... #include<iostream.h>

class circle
{
private:
double radius;
public:
circle();
circle(double x);
friend int operator == (circle c1,circle c2);
friend int operator > (circle c1,circle c2);
friend void compare(circle c1,circle c2);
}

circle::circle()
{radius=(double)0;}

circle::circle(double x)
{radius=x;}

int operator == (circle c1,circle c2)
{
if (c1.radius==c2.radius)
return 1;
else
return 0;
}

int operator > (circle c1,circle c2)
{
if c1.radius>c2.radius
return 1;
else
return 0;
}

circle::compare(circle c1,circle c2)
{
if(c1==c2)
cout<<"c1,c2等大"<<
if(c1>c2)
cout<<"c1大于c2"<<
else
cout<<"c1小于c2"<<
}

void main()
{
circle c1(99);
circle c2(80);
compare(c1,c2);
}

编译显示的错误是:
[Error] C:\Users\fox\Documents\C-Free\Temp\未命名2.cpp:16: return type specification for constructor invalid
[Error] C:\Users\fox\Documents\C-Free\Temp\未命名2.cpp:31: parse error before `.'
[Error] C:\Users\fox\Documents\C-Free\Temp\未命名2.cpp:35: confused by earlier errors, bailing out
展开
 我来答
忘至白葬不情必0T
2011-11-09 · TA获得超过3万个赞
知道大有可为答主
回答量:1.1万
采纳率:90%
帮助的人:1.2亿
展开全部
1、类的声明结束后,}后面要加分号
2、有几句代码后面没写分号
3、compare是友元函数,不是成员函数,不用加circle::
4、cout的最后不能是<<

#include<iostream.h>

class circle
{
private:
double radius;
public:
circle();
circle(double x);
friend int operator == (circle c1,circle c2);
friend int operator > (circle c1,circle c2);
friend void compare(circle c1,circle c2);
};

circle::circle()
{radius=(double)0;}

circle::circle(double x)
{radius=x;}

int operator == (circle c1,circle c2)
{
if (c1.radius==c2.radius)
return 1;
else
return 0;
}

int operator > (circle c1,circle c2)
{
if (c1.radius>c2.radius)
return 1;
else
return 0;
}

void compare(circle c1,circle c2)
{
if(c1==c2)
cout<<"c1,c2等大";
if(c1>c2)
cout<<"c1大于c2";
else
cout<<"c1小于c2";
}

void main()
{
circle c1(99);
circle c2(80);
compare(c1,c2);
}
百度网友1fc36d4
2011-11-09 · TA获得超过3131个赞
知道大有可为答主
回答量:1497
采纳率:100%
帮助的人:1838万
展开全部
#include<iostream.h>

class circle
{
private:
double radius;
public:
circle();
circle(double x);
friend int operator == (circle c1,circle c2);
friend int operator > (circle c1,circle c2);
friend void compare(circle c1,circle c2);
};//分号

circle::circle()
{radius=(double)0;}

circle::circle(double x)
{radius=x;}

int operator == (circle c1,circle c2)
{
if (c1.radius==c2.radius)
return 1;
else
return 0;
}

int operator > (circle c1,circle c2)
{
if (c1.radius>c2.radius)//前后括号
return 1;
else
return 0;
}

//circle:://不是成员函数,去掉类域名
void compare(circle c1,circle c2)
{
if(c1==c2)
cout<<"c1,c2等大"<<endl;//不完整,注意分号结束语句
if(c1>c2)
cout<<"c1大于c2"<<endl;//不完整,注意分号结束语句
else
cout<<"c1小于c2"<<endl;//不完整,注意分号结束语句
}

void main()
{
circle c1(99);
circle c2(80);
compare(c1,c2);
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式