Home > Software engineering >  According to the following to delete the object array so what's the problem
According to the following to delete the object array so what's the problem

Time:10-01

A is an object, according to the following ways to release any problems?
A * b=new A, [10].
for(int i=0; I & lt; 10; I++)
{
The delete & amp; B [I];
}

CodePudding user response:

B is as a whole blocks of memory management, cannot separate released one of the element

X * b=new X [n]
For (... )
{
.
}
The delete [] b;

CodePudding user response:

No problem, but the redundant

A * b=new A, [10].
,,,,,,,
The delete [] b;

So you can

CodePudding user response:

Try to know
Int * b=new int [10].
//for (int I=0; I & lt; 10; I++) delete & amp; B [I];
The delete [] b;

CodePudding user response:

In the debug to run I exit the program cannot be properly I don't know what reason

CodePudding user response:

Doing so would collapse...

CodePudding user response:

Int * b=new int [10].//b is a point to 10 int array

CodePudding user response:

Int * b=new int [10].
//for (int I=0; I & lt; 10; I++) delete & amp; B [I];
//choose one of these!
The delete b;
//delete [] b;

CodePudding user response:

Why do you use an array?
The vector is not very good?

CodePudding user response:

The
refer to the original poster louchao643476 response:
A is an object, according to the following way to release any problems?
A * b=new A, [10].
for(int i=0; I & lt; 10; I++)
{
The delete & amp; B [I];
}


To think of it, it is no good, because the memory is the whole block allocation, you delete & amp; B [0], the whole piece of memory is deleted, you loop at the back of the delete & amp; B [I] is doomed to collapse,
Furthermore the delete & amp; B [0] should be you will be successful, but you delete & amp; B [I] surely fail

CodePudding user response:

No new, no delete;
No new [], no delete []

CodePudding user response:

http://blog.csdn.net/cbnotes/article/details/38900799
The real difference "delete and delete []"

CodePudding user response:

Neighbor borrowed a set of tea set, use after you try one by one?
  • Related