0
点赞
收藏
分享

微信扫一扫

Python 高级(一):HTTP 请求与响应(urllib 模块)

    Point operator++ (int) { // 后置自增运算符重载

        Point temp(*this);

        ++(*this);

        return temp;

    }

    void print() {

        cout << "x=" << x << ", y=" << y << endl;

    }

private:

    int x;

    int y;

};

int main() {

    Point p1(1, 2);

    Point p2 = ++p1;

    p1.print();

    p2.print();

    Point p3(3, 4);

    Point p4 = p3++;

    p3.print();

    p4.print();

    return 0;

}

运行结果:

2. 编写一个complex类,在类中重载运算符+,-,使其当做complex类的成员函数,完成复数的加,减。要求:

(1)定义complex类,完善构造函数。

(2)完善+,-运算符重载函数。

(3)主函数定义对象,完成加减运算,给出运行结果。

程序代码:

#include <iostream>

using namespace std;

class complex {

private:

    double real;

    double imag;

public

举报

相关推荐

0 条评论