In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "what is the destructor of C++". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The destructor (destructor), in contrast to the constructor, automatically executes the destructor when the object is out of its scope (for example, the function in which the object is located has been called). Destructors are often used to clean up the aftermath (for example, opening up a memory space with new when creating objects, which should be freed with delete in the destructor before exiting).
Some of the previous examples do not illustrate destructors because the classes used do not require special cleanup at the end. The following program gives a new Date class that includes a string pointer to represent the month.
# include\ "iostream.h\" # include\ "string.h\" class Date {int mo,da,yr; char * month; public: Date (int masking 0, int dumb0, int yearly 0); ~ Date (); void display () const;} Date::Date (int January int djinint y) {static char * mos [] = {\ "January\",\ "February\",\ "March\",\ "April\",\ "May\",\ "June\",\ "July\",\ "August\",\ "September\",\ "October\",\ "November\",\ "December\"}; mo=m; da=d; yr=y If (month; 0) {month=new char [strlen (MOSs [m-1]) + 1]; strcpy (month, MOSs [m-1]);} else month= 0;} Date::~Date () {delete [] month;} void Date::display () const {if (MOs [m-1]) cout
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: 0
*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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.