Home > Back-end >  The container into the object in question
The container into the object in question

Time:10-23

Why this code will collapse? Container into the object constructor of the new memory space, but the custom destructors release the memory program will collapse, comment out the custom destructor was no problem, but it didn't leak?

CodePudding user response:

When performing: Amy polumbo ush_back (Object ());
Now generate temporary objects, invoke the default copy constructor, and because the default copy constructor is shallow, the generated temporary objects just copy the pointer passed, leading to a temporary object is destroyed so occur secondary to release memory, go wrong,

CodePudding user response:

That you want to define the copy constructor, or it is prohibited to use the copy constructor, the usual approach is to define a yourself,

CodePudding user response:

On the cause of the crash that explains the

And the new int (4) is to do what?
Not sure to new int [4], the meaning is not a

CodePudding user response:

Fun
reference 3 floor response:
on the cause of the crash that explains the

And the new int (4) is to do what?
Not sure to new int [4], the meaning is not a
c + + 11 the initialization method and this is not an array

CodePudding user response:

reference 1/f, cold wind response: 1023
when performing: Amy polumbo ush_back (Object ());
Now generate temporary objects, invoke the default copy constructor, and because the default copy constructor is shallow, the generated temporary objects just copy the pointer passed, leading to a temporary object is destroyed so occur secondary to release memory, go wrong,
understand thanks for a great god
  • Related