10.3运算符重载

#include 

using namespace std;

//定义一个复数类
class Complex
{
private:
    int real;   //实部
    int vir;    //虚部
public:
    Complex(){}
    Complex(int r, int v):real(r),vir(v){}

    void show(){
        if(vir > 0){
            cout<(const Complex &R)const {
        return real>R.real&&vir>R.vir;
    }

    int & operator[](const int index) {
        if(1 == index){
            return vir;
        }else if(0 == index){
            return real;
        }else{
            cout<<"段错误"< c4){
        cout<< "yes" << endl;
    }else{
        cout<< "no" << endl;
    }

    c3[0] = 5;
    c3.show();

    c3 += c2 += c1;

    c1.show();
    c2.show();
    c3.show();

    Complex c5 = -c4;
    c5.show();

    return 0;
}

10.3运算符重载_第1张图片

你可能感兴趣的:(qt,开发语言,c++)