首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

大家帮小弟我指点一下这个简单小程序

2012-03-29 
大家帮我指点一下这个简单小程序#includeiostream#includeiomanipusing namespace stdclass Time{int

大家帮我指点一下这个简单小程序
#include<iostream>
#include<iomanip>
using namespace std;

class Time{
int hour,minute,second;
public:
void set(int h,int m, int s){hour=h;minute=m;second=s;}
friend Time& operator++(Time& a);
friend Time operator++(Time& a,int);
friend ostream& operator<<(ostream& o,const Time& t);
};

Time& operator++(Time& a){
if(!(a.second=(a.second+1)%60) &&! (a.minute=(a.minute+1)%60))
  a.hour=(a.hour+1)%24;
  return a;
}

Time operator++(Time& a,int){
Time t(a);
if(!(a.second=(a.second+1)%60) &&! (a.minute=(a.minute+1)%60))
  a.hour=(a.hour+1)%24;
return t;
}

ostream& operator<<(ostream& o,const Time& t){
  o<<setfill('0')<<setw(2)<<t.hour<<":"<<setw(2)<<t.minute<<":";
 return o<<setw(2)<<t.second<<"\n"<<setfill(' ');
}

void main(){
Time t;
t.set(11,59,58);
cout<<t++;
cout<<++t;
}
老是报错operator << is ambiguous hour/minute/second : cannot access private member declared in class Time/minute/second see declaration of 'hour/minute/second' ...我是按照书上写的为什么会通不过啊,我用的是vc6.0,大家帮我看一下。。谢谢了。

[解决办法]
上面是修改以后的 求分。

热点排行