cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
How to delete memory used in constructor
How to delete memory used in constructor
Apr 20, 2012 at 4:07am UTC
hopesfall
(179)
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 UTC
hamsterman
(4538)
delete
newQueue;
of course. What's the problem?
Last edited on
Apr 20, 2012 at 5:21am UTC
Apr 20, 2012 at 10:08am UTC
Peter87
(11254)
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 UTC
rollie
(304)
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.