How to delete memory used in constructor

Apr 20, 2012 at 4:07am
So I have a constructor with the following statement:

queue<T> *newQueue = new queue<T>;

How can I deallocate this memory in the constructor?

Apr 20, 2012 at 5:21am
delete newQueue; of course. What's the problem?
Last edited on Apr 20, 2012 at 5:21am
Apr 20, 2012 at 10:08am
Why not create the queue as queue<T> newQueue;? That way it will automatically be deallocated when the constructor ends.
Apr 20, 2012 at 10:38am
Or, if it really must be a pointer to a queue, you could use a smart pointer (std::auto_ptr I think, with some other options in boost if you have that available)
Topic archived. No new replies allowed.