469,571 Members | 1,696 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,571 developers. It's quick & easy.

storing suicidal classes in a container

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
1 2100
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.

Similar topics

7 posts views Thread by Snyke | last post: by
1 post views Thread by glen stark | last post: by
11 posts views Thread by toton | last post: by
5 posts views Thread by toton | last post: by
11 posts views Thread by =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.