# c++运算符+号重载

0

#include<iostream>
using namespace std;

const float PI = 3.141593;
class Point
{
public:
Point(int xx = 0, int yy = 0) {
x = xx;
y = yy;
}
Point(Point &p);
int getX() {
return x;
}
int getY() {
return y;
}
~Point() {}
private:
int x, y;
};
class Circle :public Point {
public:
friend Circle operator+(const Circle& circle1,const Circle& circle2);
Circle(float r);
Circle();
float area();
//float operator+(Circle &c2) const;
~Circle() {}
private:
};
Point::Point(Point &p) {
x = p.x;
y = p.y;
}
Circle::Circle(float r) {
}
Circle::Circle() {
}

float Circle::area() {
}
/*float Circle::operator + (Circle &circle2) const {
}*/
int main() {
float sum;
Point b(4, 5);
cout << b.getX() << endl << b.getY() << endl;
cout << "Enter the radius of Circle:";
Circle circle1(3);
float area1 = circle1.area();

Circle circle2(4);
float area2 = circle2.area();
cout << "Circle1 area is" << area1 << endl;
cout << "Circle2 area is" << area2 << endl;
cout << "sum of area1 and area2 is\n" << area1 + area2 << endl;
sum = circle1+circle2;
float area;
//area = circle1 + circle2;
cout << "area = " << area << endl;

return 0;
}
Circle operator+(const Circle& circle1,const Circle& circle2)
{
}

/*

/*float Circle::operator + (Circle &circle2) const {
}*/用这种方式float area;
//area = circle1 + circle2;可以返回float的area

0

``` 1 Circle operator+(const Circle& circle1,const Circle& circle2)
2 {
4 }
5
6 //以上是利用列表初始化的方法
7 //或者
8 Circle operator+(const Circle& circle1,const Circle& circle2)
9 {