Topic: STL question
Author: "Warwick Molloy" <wmolloy@optushome.com.au-nospam>
Date: Mon, 23 Jul 2001 19:07:55 GMT Raw View
In article <3b571460$1@post.newsfeeds.com>, "chang"
<chang_shen@progressive.com> wrote:
> If I have a class using STL and in the construction it allocates memory.
> When I
> destory the object, does this memory been freed.
>
No. That's what the destructor is for.
You must include a destructor to destroy or clean up any resource use
(including memory) made by your classes instance. This remains true when
contained in an STL container or not.
A destructor can be used to close a file, free memory or any other clean
up action required. By the way: malloc/free should be dropped in favour
of new/delete in C++.
Regards,
Warwick.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: admin@rzaix13.uni-hamburg.de ()
Date: 1995/07/11 Raw View
The following simple program compiles well with Borland 4.5:
#include "map.h"
int main()
{
map<char, unsigned, less<char> > m;
return 0;
}
But when compiled with xlC, it yields an error message:
"/local/stl/tree.h", line 56.12: 1540-222: (S)
"rb_tree<char,pair<const char,unsigned int>,select1st<pair<const char,
unsigned int>,char>,less<char> >::rb_tree_node" needs a constructor
because class member "value_field" needs a constructor initializer.
"tst.C", line 6.9: 1540-207: (I) The previous message applies to the
definition of template "map<char,unsigned int,less<char> >".
"/local/stl/defalloc.h", line 74.16: 1540-252: (W) The destructor for
"pair<const char,unsigned int>" does not exist. The call is ignored.
"/local/stl/defalloc.h", line 73.13: 1540-207: (I) The previous message
applies to the definition of template "destroy(pair<const char,unsigned int>*)".
This looks like a bug to me, because "value_field" is "unsigned" here,
and "unsigned" shouldn't need a constructor initializer.
Could anybody comment on this?
Thanks,
Bernd
--
+----------------------------------+
| Bernd Eggink |
| Rechenzentrum Uni Hamburg |
| admin@rzaix13.rrz.uni-hamburg.de |
+----------------------------------+