|
| ||||||||||
| Tags: deleting pointers, pointers, programming, software language |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Deleting the same pointer twice in C++
|
|
#2
| ||||
| ||||
| Re: Deleting the same pointer twice in C++
Even I am not that good with C++ programming because I am also in the process of learning it. But I can help you with definition of pointer. A pointer in C++ is said to point to the memory location which is stored in it. In other words, a pointer variable contains the memory address where the actual object can be found. In C++ while defining pointers we have also specify the type of variable to which it is pointing. . |
|
#3
| |||
| |||
| Re: Deleting the same pointer twice in C++ Code: class xyz
{
.
.
.
};
void disp()
{
xyz* X = new xyz();
delete X; // first delete
delete X; // second delete
.
.
.
} The second delete X is capable of generating unwanted consequences . This includes crashing your program, corrupting your heap, making bizare and unwanted changes to obkects that are already existing on heap, etc. So hence in C++, never Delete a Pointer twice as the pointer is reletad to a memory location directly. |
|
#4
| ||||
| ||||
| Re: Deleting the same pointer twice in C++
When you delete the pointer, it still points to the same place - the only difference is that the place was marked as "free" in some system-specific way. This memory location is free and now might be allocated for some other data. Deleting it second time might be problematic as it's no longer free. The second call to delete will probably try to mark it as "free" again. Thus with the second delete the memory location on heap that you are deleting is now been used by some othe object data. Never try to do this in C++.
__________________ The FIFA Manager 2009 PC Game |
|
#5
| |||
| |||
| Re: Deleting the same pointer twice in C++
hey can u explain me heap concept related to memory management......... ![]() |
|
#6
| ||||
| ||||
| Re: Deleting the same pointer twice in C++
The heap is reserved for the memory allocation needs of the program. It is an area apart from the program code and the stack. Typical C programs use the functions malloc and free to allocate and deallocate heap memory. The Debug version of MFC provides modified versions of the C++ built-in operators new and delete to allocate and deallocate objects in heap memory. More information can be found here.
__________________ Education, Career and Job Discussions |
|
#7
| |||
| |||
| Re: Deleting the same pointer twice in C++
Thanks for the info...... |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Deleting the same pointer twice in C++" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Changing Stylus pointer to normal Pointer in Tablet PC | Kelley | Portable Devices | 3 | 21-06-2011 07:22 PM |
| Email Not Deleting Off Server When Deleting From Email Screen On HTC Sense UI | Mahatma | Portable Devices | 4 | 20-04-2010 11:56 AM |
| Can we use pointer in C#? | Zoey Mod | Software Development | 5 | 29-01-2010 09:49 AM |
| Differentiation between void pointer and null pointer | Ram Bharose | Software Development | 5 | 18-01-2010 11:11 AM |
| How can you prevent deleting folders but allow deleting files | a.dorst | Operating Systems | 1 | 24-08-2009 09:47 PM |