943,650 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 6881
  • C++ RSS
Aug 1st, 2004
0

compile error-chained hash table c++

Expand Post »
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;
}[/SIZE]



[SIZE=1]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;

}
Last edited by Nick Evan; Nov 21st, 2010 at 9:39 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
andremc is offline Offline
3 posts
since Aug 2004
Aug 1st, 2004
0

Re: compile error-chained hash table c++

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.
Reputation Points: 36
Solved Threads: 11
Posting Pro in Training
Chainsaw is offline Offline
436 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Find function
Next Thread in C++ Forum Timeline: Bellman Ford Algo





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC