逗号运算符重载 p139 todo 编译失败

//
// Created by 刘彪 on 2020/2/29.
//

//逗号运算符重载 p139  todo 编译失败
#include <iostream>
#include <cstdio>
#include <malloc.h>

using namespace std;
class Point{
    int x,y;
public:
    Point(){}
    Point(int l,int w){
        x = l;
        y = w;
    }
    void disp(){
        cout << "面积:"<<x*y<<endl;
    }
    Point operator,(Point r){
        Point temp;
        temp.x = r.x;
        temp.y = r.y;
        return temp;
    }
    Point operator+=(Point r){
        Point temp;
        temp.x = r.x+x;
        temp.y = r.y+y;
        return temp;
    }

};
int main(){
    Point r1(3,3),r2(5,8),r3(2,4);
    r1.disp();
    r2.disp();
    r3.disp();
    r1 = (r1,r2,r3);
    r1.disp();

    return 0;
}

全部评论

相关推荐

Java面试先知:我也是和你一样的情况,hr 说等开奖就行了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务