這是我的頭文件,但我不明白靜態數據成員的功能,如果我聲明它們是私有的或公共的輸出保持不變。靜態數據成員如何工作。關於靜態數據成員。
class cDate
{
private:
int day;
int month;
int year;
bool valid;
bool validate();
bool IsLeapYear() const;
**static char strMON[12][4];
static char strMONTH[12][10];**
public:
cDate(int d = 1, int m = 1, int y = 2000);
cDate(cDate & src);
~cDate();
void print(int option) const;
void ReadFromKB();
void setDay(int d);
void setMonth(int m);
void setYear(int y);
void setDate(int d, int m, int y);
int getDay() const;
int getMonth() const;
int getYear() const;
};
一些指導:使用'std :: vector'而不是原始數組和指針;使用'std :: string'而不是'char'數組;考慮更改命名約定,以便客戶端代碼很好地讀取(僅使用'day()')而不是很好地讀取的實現代碼。 –
對於不起作用的代碼,請提供一個完整但很小的例子,讀者可以嘗試。 –
@Noman你是否嘗試過使用'cDate'的多個實例? – LogicStuff