| delorie.com/archives/browse.cgi | search |
| From: | deepblack AT geocities DOT com (Luis Coelho) |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Re: destructors for C++ classes. |
| Date: | Sun, 28 Feb 1999 11:37:45 GMT |
| Organization: | Universidade Tecnica de Lisboa |
| Lines: | 48 |
| Message-ID: | <36d89aeb.9035791@news.ist.utl.pt> |
| References: | <36d7c7dc DOT 49356683 AT news DOT uea DOT ac DOT uk> |
| NNTP-Posting-Host: | ppp133.ist.utl.pt |
| X-Newsreader: | Forte Free Agent 1.1/32.230 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
On Sat, 27 Feb 1999 10:36:59 GMT, T DOT Mcdonald AT uea DOT ac DOT uk (Terry
McDonald) uttered the following words:
>class Parse
>{
>private:
> vector<string> words;
>public:
> Parse(string phrase);
> int numWords(void);
> string operator[](int elem);
> //~Parse();
>};
>I want to destruct the xyzzy at the end of every x loop before it is
>re-constructed to parse the next senatance entered. Every time I try
>to write a destructor I get errors. I've tryed the following:
>
>Parse::~Parse
>{
> ~words;
>}
How about
<code>
Parse::~Parse
{
; // do nothing
}
</code>
In fact you don't need to anything at all! words is declared as
> vector<string> words;
Both class string and class vector take care of their memory in
their destructors (which are called automatically) you don't have
to worry about it, that's the whole idea behind using a string &
a vector instead of a plain
char** words;
Hope that helped.
Luis Coelho.
C++ Programming Language, 3rd Ed. by B. Stroustrup. My exercise answers at:
http://www.geocities.com/SiliconValley/Way/3972/index.html
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |