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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top