建立一個time類別,包含3個整數變數,
分別去記錄時/分/秒,變數名稱自行設定,寫出一個建構子。
初始值設為0
我這樣寫不知有没有錯..請高手解答.謝謝
class Time
{
private:
int hour;
int min;
int sec;
public:
Time();
};
Time::Time()
{
hour=0;
min=0;
sec=0;
}
2006-12-03 14:52:47 · 2 個解答 · 發問者 ? 1 in 電腦與網際網路 ➔ 程式設計
Normally, we do it as:
class Time
{
private:
int hour;
int min;
int sec;
public:
Time(): hour(0),min(0),sec(0) {};
//Or
Time(int hh,int mm, int ss): hour(hh),min(mm),sec(ss) {};
};
2006-12-03 15:29:38 · answer #1 · answered by ? 4 · 0⤊ 0⤋
…類別,…預設建構子,呃…沒錯誤。
2006-12-03 15:09:35 · answer #2 · answered by Big_John-tw 7 · 0⤊ 0⤋