⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 自增自减运算符的重载.cpp

📁 学C++的同学是不是遇到麻烦了
💻 CPP
字号:
#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 ++();
	   Date   operator --();
    private:
         int   year ,  month,  day;
};
Date  Date::operator ++()
{
	day++;
	return  *this;
}
Date  Date::operator --()
{
	day--;
	return  *this;
}

void  main()
{
   Date  today(2003,10,13),tomorrow,yesterday;
   cout<<"Today  is  ";
   today.Print();
   cout<<"Tomorrow  is   ";
   tomorrow=++today;
   tomorrow.Print();
   cout<<"Yesterday  is  ";
   today=--tomorrow;
   yesterday=--today;
   yesterday.Print();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -