引用传递出现错误

#include<bits/stdc++.h>
using namespace std;
class Time
{
private:
    int h_,m_,s_;
public:
    Time():h_(0),m_(0),s_(0) { }
    Time(int h,int m,int s):h_(h),m_(m),s_(s) {  }
    Time(const Time& rhs){ h_=rhs.h_; m_=rhs.m_; s_=rhs.s_;  }
    Time(Time& rhs){ h_=rhs.h_; m_=rhs.m_; s_=rhs.s_; }
    Time& operator = (Time& x){ *this=x; return x; }
    ~Time() {}
    Time& operator++()
    {
        int n;
        if(h_>=24||h_<0||m_<0||m_>=60||s_<0||s_>=60) { }
        else
        {
        n=h_*60*60+m_*60+s_;
        n+=1;
        if(n>=24*60*60)
        {
        n-=24*60*60;
        h_=n/60/60%24;
        m_=n/60%60;
        s_=n%60;
        }
        else
        {
        h_=n/60/60%24;
        m_=n/60%60;
        s_=n%60;
        }
        }
        return *this;
    }
    /*
    Time& operator++(int)
    {
        //Time p(*this);

        int a=h_;
        int b=m_;
        int c=s_;
//            cout<<a<<b<<c<<endl;

//        int n;
//        if(h_>=24||h_<0||m_<0||m_>=60||s_<0||s_>=60) { }
//        else
//        {
//        n=h_*60*60+m_*60+s_;
//        n+=1;
//        if(n>=24*60*60)
//        {
//        n-=24*60*60;
//        h_=n/60/60%24;
//        m_=n/60%60;
//        s_=n%60;
//        }
//        else
//        {
//        h_=n/60/60%24;
//        m_=n/60%60;
//        s_=n%60;
//        }
//        }
        Time t(a,b,c);
//        cout<<endl<<p.h_<<p.m_<<p.s_<<endl;
        return t;
    }
    */
    Time& operator ++(int){
       Time t=*this;
       return t;
    }
    Time& operator--()
    {
        int n;
        if(h_>=24||h_<0||m_<0||m_>=60||s_<0||s_>=60) { }
        else
        {n=h_*3600+m_*60+s_;
        n-=1;
        if(n<0)
        {
        n+=86400;
        h_=n/3600%24;
        m_=n/60%60;
        s_=n%60;
        }
        else
        {
        h_=n/3600%24;
        m_=n/60%60;
        s_=n%60;
        }
        }
        return *this;
    }
    Time& operator--(int)
    {
        //Time p(*this);
        int a,b,c;
        a=h_;b=m_;c=s_;
        Time p(a,b,c);
//        int n;
//        if(h_>=24||h_<0||m_<0||m_>=60||s_<0||s_>=60) { }
//        else
//        {n=h_*3600+m_*60+s_;
//        n-=1;
//        if(n<0)
//        {
//        n+=86400;
//        h_=n/3600%24;
//        m_=n/60%60;
//        s_=n%60;
//        }
//        else
//        {
//        h_=n/3600%24;
//        m_=n/60%60;
//        s_=n%60;
//        }
//        }
        return p;
    }
    friend istream& operator >> (istream& in,Time& x){
        in>>x.h_>>x.m_>>x.s_;
        return in;
    }
    friend ostream& operator << (ostream& out,Time& x){
        cout<<"********"<<x.h_<<"___"<<x.m_<<"____"<<x.s_<<"*********"<<endl;
        if(x.h_>=0&&x.h_<=23&&x.m_>=0&&x.m_<=59&&x.s_>=0&&x.s_<=59)
        out<<setw(2)<<setfill('0')<<x.h_<<":"<<setw(2)<<setfill('0')<<x.m_<<":"<<setw(2)<<setfill('0')<<x.s_;
        else  out<<"error!!!";
        return out;
    }



};



int main()
{
    Time t;
    int cases;
    cin>>cases;
    cout<<setw(8)<<left<<"++t"<<" ";
    cout<<setw(8)<<left<<"--t"<<" ";
    cout<<setw(8)<<left<<"t"<<" ";
    cout<<setw(8)<<left<<"t--"<<" ";
    cout<<setw(8)<<left<<"t++"<<" ";
    cout<<setw(8)<<left<<"t"<<right<<endl;
    for(int i = 1; i <= cases; ++i)
    {
        cin>>t;
        Time c =  t;
        cout<<"&&&"<<c<<"&&"<<endl;
//        cout<<(++t)<<" ";
//        cout<<(--t)<<" ";
//        cout<<t<<" ";
//        cout<<t--<<" ";
        cout<<"**"<<t++<<"*** ";
//        cout<<t<<endl;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值