Latest

Archive

Community news

C++

Communities and Content

Databases

Editorials

Emacs

General

HTML

Java

Notices

PHP

XML

Apache

C++

Database

General

HTML

Java

Javascript

Linux

Object oriented programming

Open source

Perl

PHP

Python

Ruby

SOAP

XML

Suggest a link

Advertise on zez

Contribute

Contact us

About zez


RE: Need help with destructor


Categories C++ Code

Topic:

RE: Need help with destructor

Author:

Geir Haugom

Time:

30.11.2000 19:07

Text:

I wrote:
> class Bintre {
> private:
> int tall;
> Bintre* left;
> Bintre* right;
> };
>
Danny wrote:
> It would be helpful if you explained if the pointers formed an array or maybe a b-tree because of the naming. Is it something else?
>
> If it were just an array of Bintre then...
>
> delete [] right;
> delete [] left;
>
> If it were a b-tree, you would have to traverse to the bottom leaves and delete the on your way up until there was none left (could be done recursively as shown below).
>
> void Bintre::deleteNode(Bintre *ptr)
> {
> if (ptr-getLeft())
> deleteNode(ptr-getLeft());
> if (ptr-getRight())
> deleteNode(ptr-getRight());
> deleteNode(ptr);
> }
>

It's a b-tree (not an array)
I think the above example will work. Thanks.

I wrote:
> Every time I try to write some kind of destructor to "clean up", my program always crash upon exit or display the
> "null pointer assignment" upon exit..
>
Danny:
> Was the pointer null when you tried to delete it?
>

Yes. When I use a pointer of some kind, I always try:
ptr = NULL;
delete ptr;

and then on program exit I get "Null pointer assignment"

if I leave out "ptr = NULL;"
the program crash.



Message threads

Topic: Author:
Time:
Need help with destructor Geir Haugom 14.11.2000 19:43  
  RE: Need help with destructor Danny Dorris 15.11.2000 03:41  
   RE: Need help with destructor Geir Haugom 30.11.2000 19:07  


Forgot your password?

Register a new user

Results

Polls