Ошибка E0137 выражение должно быть допустимым для изменения левосторонним значением C++
Возникает ошибка в двух последних строках: Ошибка E0137 выражение должно быть допустимым для изменения левосторонним значением.
void resize() {
int newM = M * 2;
LinkedList* newBucketsArray = new LinkedList[newM];
for (int i = 0; i < M; i++) {
LinkedList& list = bucketsArray[i];
HashNode* current = list.head;
while (current != nullptr) {
HashNode* next = current->next;
int newIndex = current->key % newM;
LinkedList& newList = newBucketsArray[newIndex];
current->next = newList.head;
newList.head = current;
current = next;
}
}
delete[] bucketsArray;
bucketsArray = newBucketsArray; // Ошибка
M = newM; // Ошибка
}
Как можно решить данную проблему?
Переделанный resize():
void resize() {
int newM = M * 2;
LinkedList* newBucketsArray = new LinkedList[newM];
for (int i = 0; i < M; i++) {
LinkedList& list = bucketsArray[i];
HashNode* current = list.head;
while (current != nullptr) {
HashNode* next = current->next;
int newIndex = current->key % newM;
LinkedList& newList = newBucketsArray[newIndex];
current->next = newList.head;
newList.head = current;
current = next;
}
}
for (int i = 0; i < M; i++) {
bucketsArray[i].head = nullptr;
}
delete[] bucketsArray;
bucketsArray = newBucketsArray; // Ошибка
}
Источник: Stack Overflow на русском