C++ 重载输出符号

1 C++ 重载输出符号.cpp

#include
using namespace std;

 struct Date{
    int year,month,day;
    Date()=default;
    Date(int y,int m, int d)
        :year(y),month(m),day(d){}
    ~Date(){}
    Date operator++(int i)
    {
        Date tmp;
        tmp.year = year;
        tmp.month = month;
        tmp.day = day;
        switch(month)
        {
        case 1:case 3:case 5:case 7:
        case 8:case 10:
            if(day == 31){
                day =1;
                month++;
            }else
                day++;
            break;
        case 4:case 6:case 9:case 11:
            if(day == 30){
                day=1;
                month++;
            }else
                day++;
            break;
        case 12:
            if(day == 31){
                day =1;
                month=1;
                year++;
            }else
                day++;
            break;
        case 2:
            if(year %4==0 && year%100 !=0 || year %400 ==0){
                if(day == 29){
                    day =1;
                    month++;
                }else
                    day++;
            }else{
                if(day == 28){
                    day =1;
                    month++;
                }else
                    day++;

            }
            break;
        default:
            break;
        }
        return *this;
    }
friend ostream & operator<<(ostream &cout, Date d);
 };
ostream & operator<<(ostream &cout, Date d)
{
    cout<year<<"-"<month<<"-"<day;
    return cout;
}


/*
ostream cout;
cout<int);
    operator<<(string);
    operator<<(Date){...}
};
*/
int main()
{
    Date d1(2015,8,31);
    d1++;
    cout<

你可能感兴趣的:(c++,c++-运算符重载,C++,运算符重载,c++-重载)