| | |
compile error-chained hash table c++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2004
Posts: 3
Reputation:
Solved Threads: 0
i'm trying to create a chained hash table using a linked list header file, but there's a problem with my insert function. here's the relevant portion. the error comes in the part that is in red. compiler says "parse error before '.' "
i've used the linked list header before, so i know it works. also, if i take the line in question & replace LinkedList.add(value) with 25 (for example) it works fine - of course, it just inserts it in the hash table array. i think i'm using the LinkedList.add() function incorrectly. can anyone help?
#include "linkedlist.h"
int main()
{
HashTable Hash7(7);
LinkedList MyList;
Hash7.Insert(8);
system("PAUSE");
return 0;
}
bool HashTable::Insert(const Item &value){
int Pos = HashFunction(value);
//LinkedList.add(3); gave same error
//MyList.add(value); gave error "MyList undeclared"
MyTable[Pos].status = Occupied;
MyTable[Pos].value = LinkedList.add(value);
cout<<"value in pos "<<Pos<<" is "<< MyTable[Pos].value<<endl;
}
i've used the linked list header before, so i know it works. also, if i take the line in question & replace LinkedList.add(value) with 25 (for example) it works fine - of course, it just inserts it in the hash table array. i think i'm using the LinkedList.add() function incorrectly. can anyone help?
#include "linkedlist.h"
int main()
{
HashTable Hash7(7);
LinkedList MyList;
Hash7.Insert(8);
system("PAUSE");
return 0;
}
bool HashTable::Insert(const Item &value){
int Pos = HashFunction(value);
//LinkedList.add(3); gave same error
//MyList.add(value); gave error "MyList undeclared"
MyTable[Pos].status = Occupied;
MyTable[Pos].value = LinkedList.add(value);
cout<<"value in pos "<<Pos<<" is "<< MyTable[Pos].value<<endl;
}
LinkedList is a class, not a variable. It's sort of like saying
int = 4;
LinkedList MyList;
MyList.add( value ); // this would work
LinkedList.add(value); // this wont
Also, you have a comments saying MyList.add(value) doesn't work in the Insert() function. That's because MyList is declared in the main function. The basic rule is that any variable inside brackets ( {} ) is only visible inside those brackets. So move MyList outside main() if you want to access it elsewhere, or pass it in as a parameter.
int = 4;
LinkedList MyList;
MyList.add( value ); // this would work
LinkedList.add(value); // this wont
Also, you have a comments saying MyList.add(value) doesn't work in the Insert() function. That's because MyList is declared in the main function. The basic rule is that any variable inside brackets ( {} ) is only visible inside those brackets. So move MyList outside main() if you want to access it elsewhere, or pass it in as a parameter.
![]() |
Similar Threads
- Having trouble with hash table (C++)
- Hash Table Implementation (C++)
- Reading txt file into Hash Table (C++)
- Advice: Hash table, C++ GUI (C++)
- sucinct example of hash table w/ chaining (C)
- Hash Table template implementation help (C++)
Other Threads in the C++ Forum
- Previous Thread: Find function
- Next Thread: Bellman Ford Algo
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





