In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the C++ class and object date class how to achieve, the article is very detailed, has a certain reference value, interested friends must read it!
1. Laying the groundwork before realization
Before implementing, we need to write the class, which contains member functions and member variables.
For the date class, the copy construction and assignment operators don't have to be written, but it doesn't matter if I write it in the class.
# includeusing std::cout;using std::endl;using std::cin;class Date {public:// constructor Date (int year = 0, int month = 1, int day = 1) {if (year > = 0 & & month > 0 & & month0 & & day = inline bool operator > = (const Date& d); / / GetMonthDay (_ year, _ month)) {_ day-= GetMonthDay (_ year, _ month); _ month++; if (_ month > 12) {_ year++ _ month = 1;}} else {* this-= (- day);} return * this;} 2.2 date-= number of days
Here, like the + = operator overload function, it is necessary to determine whether the day is positive or negative.
Date& Date::operator-= (int day) {if (day > 0) {_ day-= day; while (_ day operator overload bool Date::operator > (const Date& d) {if (_ year > d._year) {return true;} else if (_ year = = d._year) {if (_ month > d._month) {return true } else if (_ month = = d._month) {if (_ day > d._day) {return true;} return false;} 2.10 = = operator overload bool Date::operator== (const Date& d) {return _ year = = d._year & & _ month = = d._month & & _ day = = d.daylight;} 2.11 > = operator overload
Here we begin to reuse the operator overload functions of > and = =
Bool Date::operator > = (const Date& d) {return (* this > d) | | (* this = = d);} 2.12d);} 2.13
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 301
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.