0

Currently having a problem with one of the problem here, I will provide the 2 class(s) here which is required in the specification.

class listNode {
    friend class hashTable;
    string firstName;
    string lastName;
    listNode* next;
public:
    //listNode() {
    //  ;here for experiment purpose, not required by specification
    //}
    listNode(string fn, string ln) {
        firstName = fn;
        lastName = ln;
        next = NULL;
    }
    void printNode(listNode n) {
        cout << '('<< n.firstName << ", " << n.lastName << endl;
    }
};

class hashTable{
    char op;
    int bucketSize;
    listNode* hashTable[bucketSize]; //Error occurs

Following is written at the specification for hashTable.

hashTable class
- (char) op // either '+' or '- or '?'
- (int) bucketSize // via argv[2]
- (listNode *) hashTable [bucketSize]
method:

I'm trying to declare array of listNodes with the size of bucket which will be read into from a file However, I can't declare it but it was possible if I do this:

listNode* hashTable[25]; //No error

It will produce error if:

listNode* hashTable[bucketSize]; //Error occurs

or

int bucketSize = 23;

listNode* hashTable[bukcetSize]; //Error

I was thinking about using vector but, specification has to be followed.

This is the error that I get from Visual Studio: (E0245) nonstatic member reference must be relative to a specific object

  • Does [this](https://stackoverflow.com/questions/1887097/why-arent-variable-length-arrays-part-of-the-c-standard) help answer your question? – Nathan Pierson Feb 20 '21 at 04:40
  • Also, you're not declaring an "array of class"; you're declaring an array of *pointers* to classes. – Nicol Bolas Feb 20 '21 at 04:49

0 Answers0