以下是程序
class Time
{
private:
int hours;
int minutes;
public:
Time();
Time(int h,int m=0);
void AddMin(int m);
void AddHr(int h);
void Reset(int h=0,int m=0);
friend Time operator+(const Time & t1,const Time t2);
friend Time operator-(const Time & t1,const Time t2);
friend Time operator*(double n,const Time t);
void Show() const;
};
......
Time operator+(const Time & t1,const Time &t2)
{
Time sum;
sum.minutes=t1.minutes+t2.minutes;
sum.hours=t1.hours+t2.hours+sum.minutes/60;
sum.minutes%=60;
return sum;
}
Time operator-(const Time & t1,const Time &t2)
{
Time diff;
int tot1,tot2;
tot1=t1.minutes+60*t1.hours;
tot2=t2.minutes+60*t2.hours;
diff.minutes=(tot2-tot1)%60;
diff.hours=(tot2-tot1)/60;
return diff;
}
Time operator*(double n,const Time & t)
{
Time result;
long totalminutes = t.hours*n*60+minutes*n;
result.hours=totalminutes/60;
result.minutes=totalminutes%60;
return result;
}
......
编译的时候说不能读取类的私有数据成员。那么应该如何改正?重载操作符时应该注意些什么呢??