By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,898 Members | 2,006 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,898 IT Pros & Developers. It's quick & easy.

storing suicidal classes in a container

P: n/a
Hi,
I need to store some suicidal class to a container like deque. ( I am
not using boost container library for pointers at this moment, using
stl containers).
The container stores some session class (not pointer, the class
itself). But when the session terminates, I want the classes to commit
suicide (using a drop /dispose method). And as soon as it commits
suicide (i.e the session is closed by the user, and it calls suicide),
I want it to get removed from the deque. How to do it automatically ,
i.e. session class drop will remove itself from the container & delete
itself, rather than externally removing it from the container.
Is it better to store the pointer of the session in the deque? Any
case the session is only exists in the session deque, nowhare else,
thus no shared_ptr kind of thing is there. also all of the session
should exit as soon as the session deque exists (i.e the program
termination, the deque is attached to the application class itself).
There is no other owner of the session's rather than the deque.

abir

Sep 25 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
toton wrote:
Hi,
I need to store some suicidal class to a container like deque. ( I am
not using boost container library for pointers at this moment, using
stl containers).
The container stores some session class (not pointer, the class
itself). But when the session terminates, I want the classes to commit
suicide (using a drop /dispose method). And as soon as it commits
suicide (i.e the session is closed by the user, and it calls suicide),
I want it to get removed from the deque. How to do it automatically ,
i.e. session class drop will remove itself from the container & delete
itself, rather than externally removing it from the container.
Is it better to store the pointer of the session in the deque? Any
case the session is only exists in the session deque, nowhare else,
thus no shared_ptr kind of thing is there. also all of the session
should exit as soon as the session deque exists (i.e the program
termination, the deque is attached to the application class itself).
There is no other owner of the session's rather than the deque.
You don't need to delete this. boost::shared_ptr will manage the
deletion automatically when the element is removed from the container
or the container is destroyed. Just make sure that your destructor
doesn't throw up.

Regards,
Bart.

Sep 25 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.