what is dangling pointer, how it ishappen in program, what isthe solution
What is a dangling pointer, and how to avoid it?
Collapse
X
-
Tags: None
-
Right now I am working on J2EE means Java.Originally posted by sreenadh494what is dangling pointer, how it ishappen in program, what isthe solution
I totally Detached C or C++ or VC++ what I worked for 2 or 3 years.
But now a days I have look after those if I get time except my Project Works.
As far as I know, Dangling of pointer....When a pointer refers an Object which is already got destroyed.
And what is cause..It may be from our wrong Coding or some others.
I am not sure about the others.
And if the problems arised from you then the solution is in your Hand.
You need to take care of Object Construction and Destruction.
Kind regards,
Dmjpro. -
Dangling pointer is a pointer that points to an object that is already deleted. The following code illustrates this situation:Originally posted by sreenadh494what is dangling pointer, how it ishappen in program, what isthe solution
A popular technique to avoid dangling pointers is to use smart pointers. Please search google to know more about smart pointers.Code:MyClass* p(new MyClass); MyClass* q = p; delete p; p->DoSomething(); // p is now dangling! p = NULL; // p is no longer dangling q->DoSomething(); // q is still dangling!
RegardsComment
-
There's also a ver nice article in the C/C++ Articles section about "handles"Originally posted by zodilla58A popular technique to avoid dangling pointers is to use smart pointers. Please search google to know more about smart pointers.
which can do exactly what the OP wants.
kind regards,
JosComment
Comment