Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

c++ Simple Class Question

Name: Anonymous 2007-06-27 0:40 ID:CjAL5fOI

I have a class called htable, when it reaches a certain size it will rehash itself. Heres the pseudo code:

/* Creates new table, and deletes old one. */
Htable Htable::htable_rehash(){
   make new Htable;
   add old values to new table;
        delete old table;
   return new Htable;
}

to call it I would say hashtable = hashtable .htable_rehash();

My question is this: do i need to free the memory in the old hash table in the class, or will it be deleted when i say table = table.rehash?

Name: Anonymous 2007-06-29 9:44 ID:bwlMfvJV

You use like 0 objects - it's like you just dumped some C code into a class. If you wrote it using 'C++' it would be less than half the lines. You would use <string> instead of <string.h> and <iostream> instead of <stdio>. Your code would be more readabl, easier to maintain and have less memory leaks.

int *frequencies;
char **keys;
char **values;

UGLY AND UNSAFE.
Use standard containers - such as vector and list.

Other observations: Nice comments, I don't like your indenting but hey that's style - not important, no way do I trust that code to clean up its memory, no need to prefix functions of a class with the class name (e.g. Htable::htable_print() ).

welcome to the programming world
\o/
 l
/ \

>>19 defmacro is in boost? I never knew that, amazing!

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List