9 Dec
2009
9 Dec
'09
4:30 p.m.
So, in my understanding, if i return a weak-ptr to the clients of my object, then I will be able to delete my object at time of my choosing inspite of how many number of weak-ptr references the clients may have. But after this, the weak-ptr reference becomes invalid. Am I right?
You never can *delete* an object (in the sense of invoking delete() operator), which is accessed through shared_ptr. It can be deleted by shared_ptr's deleter only. If you return to your clients weak_ptr's to a "living" object, they probably will lock() that weak_ptr in order to access the object, and the object will be deleted only after all the clients dispose their weak/shared ptrs.