Boost logo

Boost Users :

From: Vaclav (vjedlicka_at_[hidden])
Date: 2007-03-19 05:42:13


Hello,

When I reset the main pointer to an object, I want all other pointers
pointing to that object to be reset as well. Which type of smart pointer
should I use?

Example:

 boost::shared_ptr<MySillyClass> mySharedPtr1(new MySillyClass("test"));
 boost::shared_ptr<MySillyClass> mySharedPtr2 = mySharedPtr1;

 mySharedPtr1.reset();
 if(mySharedPtr2.use_count() > 0)
 {
  TRACE("still used\n");
 }
 else
 {
  TRACE("not used anymore\n");
 }

I am getting message "still used". I understand that is the normal behavior
of boost::shared_ptr. Is there a smart pointer type that would print the
second message?

Reason:
When I am done with an object, I would reset the main pointer to it and do
not want other references to that object to be able to do anything with it.

Thanks for advice!
Vaclav


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net