标签:c++ 拷贝构造 复数类构造函数 运算符重载 析构函数
#define _CRT_SECURE_NO_WARNINGS 1 #include<iostream> using namespace std; class Complex { public: void Set(double real, double image) { _real = real; _image = image; } //构造函数 Complex(double real = 1, double image = 2) { cout << "缺省构造函数" << endl; _real = real; _image = image; } //拷贝构造函数 Complex(Complex& d) { _real = d._real; _image = d._image; } //析构函数 ~Complex() { cout << "析构函数" << endl; } // void Display() { cout << _real << _image; } //等于 bool operator==(const Complex& d) { return _real * _real + _image * _image == d._real + d._real + d._image * d._image; } //小于 bool operator < (const Complex& d) { return _real * _real + _image * _image < d._real + d._real + d._image * d._image; } //大于 bool operator > (const Complex& d) { return _real * _real + _image * _image > d._real + d._real + d._image * d._image; } private: double _real; double _image; }; int main() { Complex d1; d1.Display(); return 0; }
标签:c++ 拷贝构造 复数类构造函数 运算符重载 析构函数
原文地址:http://10740184.blog.51cto.com/10730184/1736129