c++ - Pointers to automatically null when object is deleted -


say have object , 10 pointers in several other objects of varying class types. if object gets deleted, pointers have set null. interconnect object's class classes have pointers can notify them being deleted, , can set pointers null. has burden classes must notify object when deleted since object need pointer them well. way object doesn't call dereference dangling pointer when destructs , attempts notify others.

i don't confusing web of crap , i'm looking better method.

please note auto pointers , shared pointers not i'm looking - auto pointers delete object when destruct, , shared pointers same when no more shared pointers pointing it. i'm looking slick method setting pointers object null when object destructs.

"all problems in computer science can solved level of indirection" -- david wheeler

in case, work is

std::shared_ptr<object*> pp. 

when delete object, set shared object* null (e.g. *pp = 0;). other users sharing object*, , see has become null. when users gone, memory used object* freed.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -