日期类的自增和自减运算符的重载3问题.txt
来自「学C++的同学是不是遇到麻烦了」· 文本 代码 · 共 46 行
TXT
46 行
#include <iostream.h>
class Date
{
public:
Date(){}
Date(int y,int m,int d){year=y; month=m; day=d;}
void Print() {cout<<year<<","<<month<<","<<day<<endl;}
Date operator ++(int);
Date operator --(int);
private:
int year , month, day;
};
Date Date::operator ++(int)
{
day++;
return *this;
}
Date Date::operator --(int)
{
day--;
return *this;
}
void main()
{
Date today(2003,10,13),tomorrow,yesterday;
cout<<"Today is ";
today.Print();
cout<<"Tomorrow is ";
today++;
tomorrow=today;
tomorrow.Print();
cout<<"Yesterday is ";
tomorrow--;
today=tomorrow;
today--;
yesterday=today;
yesterday.Print();
int i=10;
i--;
cout<<i<<endl;
编译通得过否?
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?