当前位置:网站首页>Constructor & destructor

Constructor & destructor

2022-04-23 22:05:00 Scarcity risk humility

The constructor of a class is a special member function of a class , It will be every time When a new object of a class is created .
The name of the constructor and the name of the class are Exactly the same Of , And no type is returned , And will not return void. Constructors can be used to set initial values for certain member variables .
The destructor of a class is a special member function of a class , It will be every time Execute when deleting the created object .
The name of the destructor and the name of the class are Exactly the same Of , Just add a word in front of it ** The waves, (~)** As a prefix , It doesn't return any value , It can't take any parameters . Destructors help in jumping out of programs ( For example, closing files 、 Free up memory, etc ) Release resources before .

版权声明
本文为[Scarcity risk humility]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/113/202204232201249916.html