Hi all,

So I'm currently teaching myself about hash tables. I'm doing a programming challenge where I create a hash table that stores instances of a class Person, with data members for name, phone number, and GPA. The table uses separate chaining to take care of collisions. The node I'm using for this is called hashNode.

The error that I'm getting is one that I have never seen before. I've searched around the internet, but it appears to be quite rare in this sort of situation.
The error message is 'error: base operand of '->' has non-pointer type 'hashNode''. This error occurs every single time that I use the arrow operator with the hashNode.

This has me really baffled, since there appears to be no difference between this case and all the other times I have used such a node with a linked list.

The code for the hash table below is a work in progress, and not all of the necessary functions have been implemented, but I am hesitant to move forward with this error still cropping up.

person.h contains the Person class

#include <iostream>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <stdio.h>
#include <string>
using namespace std;

class Person{
    string name;
    string phonenumber;
    string GPA;
    Person(string name, string phonenumber);
    string getName();
    string getPhonenumber();
    void setName(string newname);
    void setPhonenumber(string newphonenumber);
    void setGPA(string);
    string getGPA();

hash.h contains the hashTable class

#include <string>
#include <iostream>
//#include "ChainNode.h"
#include "person.h"

#define MAX 200

using namespace std;

struct hashNode
        Person data;
        bool filled;
        hashNode * next;
};//end node

class hashTable {
    hashNode array[MAX];
    int hash(string);
    void prepArray();
    void tableInsert(Person p);
    void tableDelete(string);
};//end hashTable

void hashTable::tableDelete(string phonenumber)
    int index = hash(phonenumber);

void hashTable::tableInsert(Person p)
    int index = hash(p.getPhonenumber());
    hashNode hp = array[index];//hashed position
    if(hp.filled == false)
        hp->data = p;
        hp->filled = true;
        hp->next->filled = false;
    else if(hp.filled)
            hp = hp->next;
        }//end while
        //the first empty position has now been found
        hp.data = p;
        hp.filled = true;
        hp->next.filled = false;
    }//end else if
}//end tableInsert

void hashTable::prepArray()
    for(int i = 0; i < MAX; i++)
        array[i].filled = false;
    }//end for
    //all the filled tags are now set to false
}//end prepArray

int hashTable::hash(string phonenumber)
    //string str = p.getPhonenumber();
    //int size = str.size();
    int size = phonenumber.size();
    double sum;
    for(int i=0; i < size; i++)
        sum = phonenumber[i];
    }//end for

If anybody could shed any light on this, it would be greatly appreciated.

6 Years
Discussion Span
Last Post by ace8957

The "arrow" operator is used with pointers to objects to access an object's members via the pointer. From what I can tell though, your variable "hp" is not a pointer, it's an actual object. Try replacing the "arrow" operator with the "dot" operator: i.e. hp = hp.next; . The "dot" operator is used to access an object's members via the actual object. The 2 operators are not directly interchangeable.

Edited by Fbody: n/a

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.