I was adding data to the hashtable and i have to check for collision.
Well, in my strcmp its causing a crash since there is no data
and its not initialized.(i think) So, here i proceed to try to initialize it.
When i do it calls the operator= function where i dont know what to do with? whatever i try to do it just crashes. Probobly because s contains no data?
Here are my headers
Code:class hashmap { public: hashmap(int capacity); ~hashmap(void); bool get(char const * const symbol, stock& s, int& symbolHash, int& hashIndex, int& usedIndex) const; bool put(const stock& s, int& symbolHash, int& hashIndex, int& usedIndex); bool remove(char const * const symbol, stock &s, int& symbolHash, int& hashIndex, int& usedIndex); friend ostream& operator<<(ostream& out, const hashmap& h); private: stock* hashTable; size_t Tablesize; static int hashStr(char const * const symbol); // hashing function };This is where i am trying to initialize the tableCode:class stock { public: stock(char const * const symbol, char const * const name, int sharePrice, date priceDate); // sharePrice is given as a number of CENTS stock(const stock& s); // copy constructor stock(void); // default constructor char const * const getSymbol(void) const; stock& operator=(const stock& s); stock& operator=(stock const * const s); ~stock(void); // display column headers static void displayHeaders(ostream& out); // display the headers when this instance is printed // prints share price as DOLLARS // (e.g. 2483 would print out as 24.83 and 200 would print out as 2.00) friend ostream& operator<<(ostream& out, const stock& s); friend class hashmap; private: int sharePrice; char* name; char* symbol; date priceDate; int size; };
then this function is callled:Code:hashmap::hashmap(int capacity): Tablesize(capacity),hashTable( new stock[capacity] ) { for(int i=0; i<capacity; i++) hashTable[i] = NULL; }
I think i need to do a copy here of some sort. however, what ever i do with s is crashes since s contains no data. What do i need to do in that function?Code:stock& stock::operator=(stock const * const s) { name = NULL; symbol = NULL; delete name; delete symbol; strcpy(name, s->name); // crashes return *this; }



LinkBack URL
About LinkBacks



