Apr 20, 2012 at 4:07am Apr 20, 2012 at 4:07am UTC
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 Apr 20, 2012 at 5:21am UTC
delete newQueue;
of course. What's the problem?
Last edited on Apr 20, 2012 at 5:21am Apr 20, 2012 at 5:21am UTC
Apr 20, 2012 at 10:08am Apr 20, 2012 at 10:08am UTC
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 Apr 20, 2012 at 10:38am UTC
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)