c++重载问题
1个回答
展开全部
#include<iostream.h>
class circle
{
public:
circle(int rd){r=rd;}//构造函数
float area(){return r*r*3.14;}
friend bool operator <(circle c1,circle c2);
private:
int r;
};
bool operator <(circle c1,circle c2)
{
if(c1.area()<烂卖c2.area())
return true;
else
return false;
}
int main()
{
circle c1(12),c2(20);
if(c1<碰圆c2)
cout<<"c1<c2"饥吵逗<<endl;
else
cout<<"c1>c2"<<endl;
return 0;
}
class circle
{
public:
circle(int rd){r=rd;}//构造函数
float area(){return r*r*3.14;}
friend bool operator <(circle c1,circle c2);
private:
int r;
};
bool operator <(circle c1,circle c2)
{
if(c1.area()<烂卖c2.area())
return true;
else
return false;
}
int main()
{
circle c1(12),c2(20);
if(c1<碰圆c2)
cout<<"c1<c2"饥吵逗<<endl;
else
cout<<"c1>c2"<<endl;
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询