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
-
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. -
Originally posted by sreenadh494what is dangling pointer, how it ishappen in program, what isthe solution
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
-
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