- 論壇徽章:
- 1
|
#include <iostream>
using namespace std;
class Time
{
public:
Time( ){minute=0;sec=0;} //默認構(gòu)造函數(shù)
Time(int m,int s):minute(m),sec(s){ } //構(gòu)造函數(shù)重載
Time operator++( ); //聲明運算符重載函數(shù)
void display( ){cout<<minute<<":"<<sec<<endl;} //定義輸出時間函數(shù)
private:
int minute;
int sec;
};
Time Time: perator++( ) //定義運算符重載函數(shù)
{
if(++sec>=60)
{
sec-=60; //滿60秒進1分鐘
++minute;
}
return *this; //返回當(dāng)前對象值
}
int main( )
{
Time time1(34,0);
for (int i=0;i<61;i++)
{
++time1;
time1.display( );
}
return 0;
}
代碼是這樣的。
我把 ++time1; 改成 time1++;就出錯了warning C4620: no postfix form of 'operator ++' found for type 'Time', using prefix form
請教。 |
|