本文共 1346 字,大约阅读时间需要 4 分钟。
#define _CRT_SECURE_NO_WARNINGS 1#include using namespace std;class Complex{public: void Set(double real, double p_w_picpath) { _real = real; _p_w_picpath = p_w_picpath; } //构造函数 Complex(double real = 1, double p_w_picpath = 2) { cout << "缺省构造函数" << endl; _real = real; _p_w_picpath = p_w_picpath; } //拷贝构造函数 Complex(Complex& d) { _real = d._real; _p_w_picpath = d._p_w_picpath; } //析构函数 ~Complex() { cout << "析构函数" << endl; } // void Display() { cout << _real << _p_w_picpath; } //等于 bool operator==(const Complex& d) { return _real * _real + _p_w_picpath * _p_w_picpath == d._real + d._real + d._p_w_picpath * d._p_w_picpath; } //小于 bool operator < (const Complex& d) { return _real * _real + _p_w_picpath * _p_w_picpath < d._real + d._real + d._p_w_picpath * d._p_w_picpath; } //大于 bool operator > (const Complex& d) { return _real * _real + _p_w_picpath * _p_w_picpath > d._real + d._real + d._p_w_picpath * d._p_w_picpath; }private: double _real; double _p_w_picpath;};int main(){ Complex d1; d1.Display(); return 0;}
转载于:https://blog.51cto.com/10740184/1736129