关于友元函数重载单目运算符的问题
挨踢呃 2008-11-25 07:07:26 这是我写的一个友元函数重载单目运算符的代码,有点问题,++并没有执行,请大家帮我看看
#include<iostream.h>
class Clock //时钟类
{
public:
Clock(int newH=0,int newM=0,int newS=0) {H=newH; M=newM; S=newS; }
void ShowTime() { cout<<H<<":"<<M<<":"<<S<<endl; }
friend void operator ++ (Clock c); //前置
friend void operator ++ (Clock c,int);//后置private:
int H,M,S;
};
void operator ++ (Clock c) { c.S++; cout<<"前置"; }
void operator ++ (Clock c,int){ c.S++; cout<<"后置"; }
void main()
{
Clock c(12,10,22);
c.ShowTime();
c++;
c.ShowTime();
++c;
c.ShowTime();
}