C++运算符重载例子代码
来源:互联网 发布:淘宝直通车创意是什么 编辑:程序博客网 时间:2024/05/19 09:47
#include <iostream>using namespace std;class Time{private: int h,m,s;public: Time(); Time(int mh,int mm,int ms); //重载++运算符 Time operator++(int); void ShowMe(); friend ostream& operator <<(ostream& output,Time &t);};ostream& operator<<(ostream& output,Time& t){ output<<t.h<<":"<<t.m<<":"<<t.s<<endl; return output;}Time Time::operator++(int){ //保存原值 Time tmp = *this; //将原值加 s = s+1; if(s == 60) { s = 0; m = m+1; if(m==60) { m = 0; h=h+1; if(h == 24) { h = 0; } } } //返回保存的那个原值 return tmp;}Time::Time(){ h=0; m=0; s=0;}Time::Time(int mh,int mm,int ms){ h=mh; m=mm; s=ms;}void Time::ShowMe(){ cout<<h<<":"<<m<<":"<<s<<endl;}int main(){ Time t(23,58,59); t++; //(t++).ShowMe(); cout<<t; return 0;}
0 0
- C++运算符重载例子代码
- c++——多态、继承、运算符重载综合例子代码
- 运算符重载例子
- 重载++运算符的例子
- C#运算符重载例子
- 运算符重载_例子
- 运算符重载的例子
- C++-运算符重载
- [C++]重载运算符
- C#:运算符重载
- c++-++运算符重载
- C++:重载运算符
- 运算符重载(C++)
- [c++]运算符重载
- 【C++】运算符重载
- C++--------------------------------------------运算符重载
- C#:运算符重载
- C++:运算符重载
- java的堆,栈,静态代码区 详解
- uvm_object的理解
- Android Studio 关联GitHub相关操作
- AbstractQueuedSynchronizer的介绍和原理分析
- [cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: entity.NewsBean
- C++运算符重载例子代码
- 10进制数与33进制数的转换
- 【DENUVO】一代天子一代臣,这代好像有点“颓”?
- JVM学习 - 体系结构 内存模型
- Android 图案解锁
- BZOJ3244: [Noi2013]树的计数
- 面向对象介绍
- CPU缓存刷新的误解
- 深入JVM锁机制-Lock