In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the object characteristics of C++ and the relevant knowledge of what friends are. The content is detailed and easy to understand, easy to operate, and has a certain reference value. I believe that you will gain something after reading this article on the object characteristics of C++ and what friends are. Let's take a look.
Object characteristic constructor and destructor
Object initialization and cleanup are also two very important security issues.
An object or variable has no initial state, and the consequences of its use are unknown.
Similarly, if an object or variable is not cleaned up in time, it will also cause some security problems.
Constructor: the main function is to assign values to the member properties of the object when creating the object. The constructor is called automatically by the compiler without manual call.
Destructor: the main function is that the system automatically calls before the object is destroyed and performs some cleaning work.
Constructor syntax: class name () {}
1. Constructor that does not return a value or write void
two。 The function name is the same as the class name
3. Constructors can have arguments, so overloading can occur
4. The program automatically invokes the construction when the object is called, without having to call it manually, and only once.
Destructor syntax: ~ class name () {}
1. Destructor with no return value and no void
two。 The function name is the same as the class name, preceded by a symbol ~
3. Destructors cannot have parameters, so overloading cannot occur
4. The program automatically invokes the destructor before calling the object, without having to call it manually, and only once.
# initialization and cleaning of includeusing namespace std;// objects / / 1. The constructor implements the initialization operation class Person {public: / / 1 constructor / / No return value, no need to write void / / the function name is the same as the class name / / the constructor can have arguments, and when overloading / / creates an object, the constructor will call automatically and only call Person () {cout once
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.