Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: Deleteing automatic variables

Reply
Thread Tools

Re: Deleteing automatic variables

 
 
mintiSPAMBLOCK@yahoo.com
Guest
Posts: n/a
 
      07-10-2004

Blue Ocean wrote:
> Suppose I have a class. It has some members and some variables and
> all that. The methods are not important in this question.
>
> class IntSet
> {
> public:
> ...
> private:
> int threshold;
> int[] set;
> }
>
> Suppose I have a destructor and I want to make sure that all of the
> resources previously owned by this class will be given back to the
> system when an instance of the class is deleted. Should the
> destructor be:
>
> IntSet::~IntSet()
> {
> delete[] set;
> delete threshold;
> }
>
> Or should it be:
>
> IntSet::~IntSet()
> {
> delete[] set;
> }
>
> Or are both variants wrong?
>
> Thanks in advance for the help.


As others have pointed out that you can't achieve deletion on
automatic variables, however if you know your variables have a limited
scope you can simple put it in a proper scope/block as in

void foo(void)
{
.....
{

int x;
// ONLY this scope/block uses x
.....
}
// x is no longer needed.
....
}

--
Imanpreet Singh Arora
isingh AT acm DOT org

 
Reply With Quote
 
 
 
 
Thomas Matthews
Guest
Posts: n/a
 
      07-12-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> As others have pointed out that you can't achieve deletion on
> automatic variables, however if you know your variables have a limited
> scope you can simple put it in a proper scope/block as in


Perhaps a bit of picking at nits:
Automatic variables are deleted when the program execution
exits the scope that the variables are defined int. This,
to me, is "achieves deletion". One cannot force the
deletion of an automatic variable before the execution
leaves the scope (although one _can_ force the leaving
of scope).


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamically deleteing subfolder causes ASPNET2.0 website to reset msnnews.msn.com ASP .Net 10 08-22-2006 06:34 PM
Deleteing Objects from std::vector canned.net@gmail.com C++ 5 03-14-2005 09:34 PM
Deleteing automatic variables Blue Ocean C++ 3 07-12-2004 02:41 PM
Problem deleteing files Emilio ASP .Net 3 10-23-2003 05:34 PM
Deleteing index from WinXP indexing services Jack B. Pollack Computer Support 2 09-11-2003 10:40 PM



Advertisments