Expression must be a modifiable lvalue

Hello,

I was wondering if someone would please help me figure out why I am getting the following error message:

"Expression must be a modifiable lvalue"

I get this message at the following line of code:

hashtable = new nodeType*[arraySize];

This code is in the constructor for my hashtable class. Here is that code:

MyChain::MyChain()
{
arraySize = 100;
hashtable = new nodeType*[arraySize];

for (int i = 0; i < arraySize; i++)
{
hashtable[i]=nullptr;
}
}

Here is the code for that class:

struct nodeType
{
int info;
nodeType *link;
}

class MyChain
{
public:
void print() const;
void push (int val);
void deleteItem(int val);
MyChain();

private:
int arraySize;
nodeType *hashtable[100];
};

I understand that the message means that the value to the left of the = cannot be modified. I just don't understand why that's the case with that code segment.

Any guidance is appreciated.

Thanks!

Ragan
I get this message at the following line of code:

hashtable = new nodeType*[arraySize];

Look here, you can't modify the whole array directly with an assignment. You can only modify each element in the array.

1
2
3
4
5
6
7
8
9
10
11
12
class MyChain
{
public:
void print() const;
void push (int val);
void deleteItem(int val);
MyChain();

private:
int arraySize;
nodeType *hashtable[100];
};
Thank you!
Topic archived. No new replies allowed.