The class Stringbad
{
Private:
Int na;
Int nb.
Public:
Stringbad (int a, int b);
Void the show ();
};
//////////////////////////////////////
Void Stringbad: : show ()
{
Cout<" Na="& lt;
//////////////////////////////////////
Stringbad: : Stringbad (int a, int b)
{
Na=a;
Nb=b;
}
/////////////////////////////////////
Int main (int arg c, char * argv [])
{
using namespace std;
Stringbad * p=new Stringbad (5, 8);//can you tell me how to delete off
p-> Show (); The whole object p//with the new assignment?
Cout
Cout<" The delete p "& lt;
cin.get();
cin.get();
return 0;
}
C - run results of free
Na=5
Nb=8
The delete p
Na=0
Nb nb=0=8//way to ah, why?
CodePudding user response:
Have found the reason, the compiler,VC6 running result is:
Na=5
Nb=8
The delete p
Na=- 572662307
Nb=- 572662307
Fully in line with expectations
constantly trial and error, is a good way to learn c + +,
CodePudding user response:
# include & lt; iostream>The class Stringbad
{
Private:
Int na;
Int nb.
Public:
Stringbad (int a, int b);
Void the show ();
};
//////////////////////////////////////
Void Stringbad: : show ()
{
Cout<" Na="& lt;
//////////////////////////////////////
Stringbad: : Stringbad (int a, int b)
{
Na=a;
Nb=b;
}
/////////////////////////////////////
Int main (int arg c, char * argv [])
{
using namespace std;
Stringbad * p=new Stringbad (5, 8);//can you tell me how to delete off
p-> Show (); The whole object p//with the new assignment?
Cout
Cout<" The delete p "& lt;
cin.get();
cin.get();
return 0;
}
CodePudding user response:
"This sentence can only delete members na, why?"The delete not remove na nb!
CodePudding user response:
Is so delete don't believe that the compilerCodePudding user response:
After the delete, just released, the address in a short period of time using the address, no other programs before the pointer to the address or location,Generally use the delete after all need the pointer to null
CodePudding user response: