Thread: destructor for a hash Table

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    118

    destructor for a hash Table

    hi i am trying to write a destructor method for a hash table but i am having problems.My hash table contains a double linked list which i am only able to delete the linked list but not the table itself.
    Code:
    intHashTable::~intHashTable() {    for(int i=0;i<getSize();i++){
            delete table[i];
    
    
               }
    
    
    
    
    }

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You really have to show how your class actually looks like and explain why you must delete in the first place.
    Dynamic arrays can be acquired with std::vector. Linked lists can be acquired with std::list.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    118
    Quote Originally Posted by Elysia View Post
    You really have to show how your class actually looks like and explain why you must delete in the first place.
    Dynamic arrays can be acquired with std::vector. Linked lists can be acquired with std::list.
    i would like to delete my hash table thats what i am trying to do

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Well if each element or bucket contains a doubly linked list then I suspect you have more issues than cleaning up. This is a hash table so if bucket 0 has a link to an object at bucket[10] when you clean up bucket 0 depending on your impl the pointer in bucket[10] could get cleaned up as well. This means that one of the links in bucket[10] is now pointing to invalid memory or 0xFEEEFEEE in MSVS and if you attempt to delete bucket[10] the program will crash. If you set the pointers to null after you delete it will fix the crash but it will not fix the potential memory leaks.

    I've never heard of mixing a doubly linked list and a hash table and all I can say is it sounds like trouble.

    As Elysia has mentioned we need to see more code to understand what you are trying to do and how we can further assist you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. hash table
    By Aisthesis in forum C++ Programming
    Replies: 10
    Last Post: 09-22-2010, 08:58 AM
  2. Hash Table
    By Cpro in forum C++ Programming
    Replies: 3
    Last Post: 03-20-2008, 02:14 PM
  3. hash table?
    By bennyboy in forum C Programming
    Replies: 2
    Last Post: 05-10-2007, 03:06 AM
  4. hash table!
    By spank in forum C Programming
    Replies: 4
    Last Post: 04-10-2006, 11:09 AM
  5. Hash Table
    By ihsir in forum C++ Programming
    Replies: 0
    Last Post: 04-13-2002, 12:08 AM