#includeclass time { private: int hour,minute,second; public: void settime(int h,int m,int s) { hour=(h>=0&&h<24)?h:0; minute=(m>=0&&m<60)?m:0; second=(s>=0&&s<60)?s:0; } void showtime() {cout< <<':'< <<':'< <
改后
View Code
#includeclass time { private: int hour,minute,second; public: void settime(int h,int m,int s) { hour=(h>=0&&h<24)?h:0; minute=(m>=0&&m<60)?m:0; second=(s>=0&&s<60)?s:0; } void showtime() { cout< <<':'< <<':'< <
改为外联函数:
View Code
#includeclass time { private: int hour,minute,second; public: void settime(int,int,int); void showtime(); }; void time::settime(int h,int m,int s) { hour=(h>=0&&h<24)?h:0; minute=(m>=0&&m<60)?m:0; second=(s>=0&&s<60)?s:0; } void time::showtime() { cout< <<':'< <<':'< <