Possible Duplicate:
Operator overloading
我必须制定锁定方案,在卸下开采经营者时,我可以进入小时、分钟和秒钟。 这些是我的法典:
clockType.h
#include<iostream>
using namespace std;
class clockType
{
public:
clockType();
void getTime();
friend istream& operator>>(istream&, const clockType);
private:
int hr, min, sec;
}
clockType.cpp
#include<iostream>
#include clockType.h"
using namespace std;
clockType::clockType()
{
hr = 0;
min = 0;
sec = 0;
}
void clockType::getTime()
{
while(hr>=24)
hr = hr - 24;
while(min>=60)
min = min - 60;
while(sec>=60)
sec = sec - 60;
cout<<setfill( 0 )
<<setw(2)<<hr<<":"
<<setw(2)<<min<<":"
<<setw(2)<<sec<<endl;
}
istream& operator>>(istream& in, clockType cl)
{
in>>cl.hr>>cl.min>>cl.sec;
return in;
}
入境点.cpp
#include<iostream>
#include clockType.h
using namespace std;
int main()
{
clockType clock;
cout<<"Enter hr, min, sec";
cin>>clock;
clock.getTime();
return 0;
}
不存在错误。 我的问题是,当我进入时,它为什么产出00:00:00? 为什么 t;和;将其价值传给目标锁?