473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

need help deleting linked--list type tree

1
I am trying all day to make some things straight but nothing helps...

Me and my collegue have built a c++ tree of a class VO. I tend to refer to the structure as a tree and not a simple list because of its complexity.

We have reached the point where a button generates an event that returns the place of the node in the tree and we need to delete that node and everything below it...i think that this is pretty much a standard procedure.

The problem is when i try to make a " delete VOobj; " the object keeps all its pointers i.e. ToParent,ToChild and seems to have deleted only the var "name" . all objects have been created with new...thats why we are investigating "delete"

When we deal with object lists do we delete the objects(is there a way?) or only the pointers that point to the object?
Should we use a destructor? how should it be?
Jul 4 '07 #1
1 1446
weaknessforcats
9,208 Expert Mod 8TB
My first question is why you are not using a map<> or multimap<> STL container where the tree code is already written?

That aside, when you delete an object, the class destructor is called. The class destructor is to clean up the various data member before the object is destroyed. Typcially, here is where the object would disengage itself from the tree. That's all it has to do.

Recall that when objects are created that all of the data members have been created and any necessary constructors have already been called before your constructor starts. Your constructor is called as part of the object creation process. Only the compiler can create objects.

Similarly with objects being destroyed. Only the compiler can destroy an object. Therefore, the destructor is only a courtesy call by the compiler for any last minute cleanup of an obect that will be destroyed.

None of the above has anything to do with new or delete. These just allow you to create your object on the heap and to remove it from the heap. As part of the creation/deletion process the class constructor/destrcutor will be called.

Since your class has pointer members, it must have:
1) suitable constructors
2) a destructor
3) a copy constructor
4) an assignment operator

If it is missing any of these, you are headed for trouble.

Add to this the fact that about the worst thing you can do is pass pointers througout a C++ program, and you have real problems of control. I recommend you use smart pointers, or handles, instead.
Jul 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jani Yusef | last post by:
I want to create a tree of processes. The depth of the tree is given by the variable depth and the number of processes started by each node is given by the variable numberOfProcesses. Is the...
2
by: Redstone | last post by:
For a Lodging reservatgions system, I need to build in a Flowchart type Calendar. Also called a "Tape" in the lodging business. This has a list of rental units down the left side and dates along...
10
by: Tomás | last post by:
When you simply want to store a number, what integral type do you use? For instance, let's say we have the following in a Poker game: struct Card { enum Suit { Hearts, Diamonds, Spades, Clubs...
1
by: Pat | last post by:
Hi all, I have a really awkward situation that is causing memory leak problems. I'm passing data to a driver, and unfortunately, the driver code is not something I can change, and it is written...
1
by: hmoundekar | last post by:
actually i want to generate a tree structure on client side, the application is simple web based, and need to display the data extracted from the database to client in tree structure. but the problem...
1
by: ellischristina | last post by:
Hello. I am trying to find a legal type database that includes the ability to have multiple party information sections or pages. i.e. a petitioner and a respondant. Hopefully it would allow...
7
by: alternative451 | last post by:
hi, I having some problem with a void * and tree structure. i am sure tha my fuction make tree is ok, but my fuction print return adress instead of values. Main : int main() { node *n =...
2
Nepomuk
by: Nepomuk | last post by:
Recently, I found that I had associated a file type to notepad by mistake. This file type (let's just say, it has the extension .xyz) wasn't supposed to be opened by notepad - actually, it wasn't...
2
!NoItAll
by: !NoItAll | last post by:
I have a ListOf(Type that I've created that will often have well over 20-thousand entries. The type I am placing into the list looks like this: Structure MyType Dim FileName as String ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.