类定义中函数末尾分号
- C/C++ code
class TableTennisPlayer{private: enum{LIM = 20}; char firstname[LIM]; char lastname[LIM]; bool hasTable;public: TableTennisPlayer(const char* fn = "none", const char* ln="none", bool ht = false); void Name()const; [color=#FF0000]bool hasTable()const{return hasTable;}; void ResetTable(bool v){hasTable = v;};[/color]};//simple derived classclass RatedPlayer:public TableTennisPlayer{private: unsigned int rating;public: RatedPlayer(unsigned int r = 0, const char * fn = "none", const char* ln = "none", bool ht = false); RatedPlayer(unsigned int r, const TableTennisPlayer & tp); [color=#0000FF]unsigned int Rating(){return rating;} void ResetRating(unsigned int r){rating = r;}[/color]};为什么上面的红色函数要末尾添加分号,而蓝色不部分却没有
[解决办法]
不可能吧?
改了一下,倒是发现函数hasTable()与hasTable成员变量重名了.
- C/C++ code
class TableTennisPlayer{private: enum {LIM = 20}; char firstname[LIM]; char lastname[LIM]; bool _hasTable;public: TableTennisPlayer(const char* fn = "none", const char* ln="none", bool ht = false); void Name() const; bool hasTable() const { return _hasTable; } void ResetTable(bool v) { _hasTable = v; }};//simple derived classclass RatedPlayer:public TableTennisPlayer{private: unsigned int rating;public: RatedPlayer(unsigned int r = 0, const char * fn = "none", const char* ln = "none", bool ht = false); RatedPlayer(unsigned int r, const TableTennisPlayer& tp); unsigned int Rating() { return rating; } void ResetRating(unsigned int r) { rating = r; }};
[解决办法]