重载单目运算符练习题
来源:互联网 发布:mac最好用的虚拟机 编辑:程序博客网 时间:2024/05/16 09:32
#include<iostream>
using namespace std;
class Time
{
public:
Time(){minute=0;sec=0;}
Time(int m,int s){minute=m;sec=s;}
Time operator++();
Time operator++(int);
void display(){cout<<minute<<":"<<sec<<endl;}
private:
int minute;
int sec;
};
Time Time::operator++()
{
if(++sec>=60)
{
sec-=60;
++minute;
}
return *this;
}
Time Time::operator ++(int)
{
Time temp(*this);
sec++;
if(sec>=60)
{
sec-=60;
++minute;
}
return temp;
}
int main()
{
Time t1(34,59),t2;
cout<<"t1:";
t1.display();
++t1;
cout<<"++t1:";
t1.display();
t2=t1++;
cout<<"t2:";
t2.display();
}
using namespace std;
class Time
{
public:
Time(){minute=0;sec=0;}
Time(int m,int s){minute=m;sec=s;}
Time operator++();
Time operator++(int);
void display(){cout<<minute<<":"<<sec<<endl;}
private:
int minute;
int sec;
};
Time Time::operator++()
{
if(++sec>=60)
{
sec-=60;
++minute;
}
return *this;
}
Time Time::operator ++(int)
{
Time temp(*this);
sec++;
if(sec>=60)
{
sec-=60;
++minute;
}
return temp;
}
int main()
{
Time t1(34,59),t2;
cout<<"t1:";
t1.display();
++t1;
cout<<"++t1:";
t1.display();
t2=t1++;
cout<<"t2:";
t2.display();
}
- 重载单目运算符练习题
- 重载单目运算符
- 单目运算符重载 ++
- 单目运算符重载
- 单目运算符重载
- C++运算符重载之重载单目运算符
- 重载双目运算符和重载单目运算符
- C++之单目运算符重载
- 单目运算符的重载
- 运算符重载加法(单目)
- C++之单目运算符重载
- 单目运算符的重载
- 重载双目/单目运算符
- 单目运算符-作为成员重载
- C++ 单目运算 and 双目运算符重载complex
- 单双运算符重载
- 知识点——多态性、运算符重载、双目运算符重载实现、单目运算符重载实现
- 单目运算符“++”重载为成员函数形式
- 打开硬件加速的方法
- struts2的继承ActionSuport类的作用
- 排它平方数
- Connection to https://dl-ssl.google.com refused的解决办法
- 网站友情链接的注意事项
- 重载单目运算符练习题
- java编码浅析
- 总监理工程师代表的职责
- sql函数的使用
- hibernate list和iterate的区别
- G.1070小解
- 大话设计模式--建造者模式 Builder -- C++实现实例
- 解析xlsx文件---Java读取Excel2007
- Java学习资料(一)——Java书籍