std containers and pointers

C

cpisz

I am going to make a queue of events to be dispatched to 1 or many
event handlers. I know I read that in order to use a std container I
must implement a default constructor, a copy constructor, and an
assignment operator. However, do any of these apply if I only queue up
pointers to events and then release the allocated memory after the
event has been dispatched and processed? And is that a bad idea?
 
A

Alf P. Steinbach

* (e-mail address removed):
I am going to make a queue of events to be dispatched to 1 or many
event handlers. I know I read that in order to use a std container I
must implement a default constructor, a copy constructor, and an
assignment operator.

The requirements are copy constructible and assignable, not default
constructible.

However, do any of these apply if I only queue up
pointers to events and then release the allocated memory after the
event has been dispatched and processed?

Pointers can be copied and assigned, so they fill the requirements.

And is that a bad idea?

Raw pointers is generally a bad idea, especially for novices. Use some
smart pointer. boost::shared_ptr comes to mind; check out the Boost
library.
 

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,998
Messages
2,570,242
Members
46,834
Latest member
vina0631

Latest Threads

Top