The class MyClass
{
Protected:
Char * STR;
Public:
MyClass () {cout & lt; <"Structure" & lt;~ MyClass () {cout & lt; <"Destruction" & lt; Void myCle () {this - & gt; ~ MyClass (); }
};
Int main ()
{
MyClass * p=new MyClass;
P - & gt; MyCle ();
//delete p;
return 0;
}
CodePudding user response:
Suggest to look at c + +; A class of pointer is released, the need to manually delete. Is a class member is a pointer in the destructor is released, the two aren't the sameCodePudding user response:
The destructor is used to clean up the cursor dynamically allocated memory space in the class object,Can't clean up the class object itself takes up space,
The Delete function can,
CodePudding user response:
The delete key to do two things, the destructor call p - & gt; ~ MyClass (), as well as calling free (p);If need to use the delete new [], [], the delete [] to record the number of according to the new, circular calling the destructor,
CodePudding user response:
Normal use is not recommended during their operation, because memory release problems,You now want to manage memory, you can refer to the new overloaded the direction of knowledge,
CodePudding user response:
Delete do two things:First, the free memory
Second, calling the destructor
CodePudding user response: