Home > Back-end >  A little doubt about the delete
A little doubt about the delete

Time:10-18

A small program, three files as follows:

The main. CPP
# include & lt; Iostream>
# include "Temp. H"
using namespace std;

Int main () {
Temp * Temp=new Temp;
The delete temp.
Temp=NULL;
Temp - & gt; Say ();
return 0;
}


Temp. H
# include & lt; Iostream>
using namespace std;

The class \ {
Private:
Int * a;
int length;
int top;
Public:
Temp () {
cout<" This is in Temp & lt; "" }
Void say ();

~ Temp () {
cout<" Left Temp & lt; "" }
};


Temp. CPP

# include "Temp. H"

Void Temp: : say () {
Printf (" Hello world \ n ");
}


Running result:
This is a Temp
Left Temp
Hello World


Why I can invoke the temp say after the delete () method??

CodePudding user response:

Because the temp memory area is not covered by the others, the delete it just tells the operating system, I applied for this memory I don't have to, this memory region still exist, use it until the next person and write other things,

With disk a truth, you delete a file, only tell the operating system, I don't this paragraph of the content of the disk sector, this file will exist until the sector by others write data, that is why deleted files to restore and condition,

CodePudding user response:

Temp wasn't equal to NULL?
Why can access to get?

CodePudding user response:

Temp wasn't equal to NULL?
Why can access to get?


Temp: : say (no use) any member variables Temp, equivalent to a static function,
Call ((Temp *) NULL) - & gt; Say (), equivalent to a static function called Temp: : say ().
So there is no error,

If the Temp: : say () using the Temp member variables, a call would be AV errors,

CodePudding user response:

reference PPower reply: 3/f
temp is not equal to NULL already?
Why can access to get?


Temp: : say (no use) any member variables Temp, equivalent to a static function,
Call ((Temp *) NULL) - & gt; Say (), equivalent to a static function called Temp: : say ().
So there is no error,

If the Temp: : say () using the Temp member variables, a call would be AV error,



I mean all pointer is set to NULL can also access to the original point to address, that also can rest assured use NULL pointer?
What on earth, is set to NULL Pointers mean?

CodePudding user response:

reference 4 floor u012174761 response:
Quote: reference PPower reply: 3/f


I mean all pointer is set to NULL can also access to the original point to address, that also can rest assured use NULL pointer?


There is no

CodePudding user response:

Pointer is set to NULL, the access is at address 0, is not the original address,

But static function, does not use any variable, the address is what all don't,

CodePudding user response:

Change, you will find problems
Int main () {
Temp * TMP=new Temp;
Delete the TMP;
TMP=NULL;
Temp - & gt; Say ();
return 0;
}

> You define the class as well as the new class name,
Temp in the building of a program, generated directly, then you can reference behind the class, also can create a new subclass,
  • Related