C++ 运算符重载

(Operator) 加分  减法  []的重载 

#include 
using namespace std;

class time1
{
    public:
        time1(){shi=0;fen=0;miao=0;}
        time1(int shi, int fen, int miao)
        {
            this->shi = shi;
            this->fen = fen;
            this->miao = miao;
        }
        time1 operator+ (time1 &i)
        {
            time1 ti;
            ti.shi = this->shi+i.shi;
            ti.fen = this->fen+i.fen;
            ti.miao = this->miao+i.miao;
            if(ti.miao >= 60)
            {
                ti.miao=ti.miao-60;
                ti.fen = ti.fen+1;
            }
            return ti;
        }
        time1 operator- (time1 &i)
        {
            time1 tp;
            tp.shi = this->shi-i.shi;
            tp.fen = this->fen-i.fen;
            tp.miao = this->miao-i.miao;
            return tp;
        }
        time1 operator+ (int i)
        {
            time1 tp;
            tp.shi = this->shi;
            tp.fen = this->fen;
            tp.miao = this->miao+i;
            if(tp.miao >= 60)
            {
                tp.miao=tp.miao-60;
                tp.fen = tp.fen+1;
            }
            return  tp;

        }
        int operator[](int i)
        {
            int sex = 0;
            if(i == 0)
            {
            sex = this->miao;
            }
            else if(i == 1)
            {
                sex = this->fen;
            }
            else
            {
                sex = this->shi;
            }
            return sex;
        }



        void show(){cout<

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