storing suicidal classes in a container

T

toton

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
 
B

Bart

toton said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top