我有排序功能:
void countingSort(TPhone * const * array, int count) {
// some code
// making copy od array
TPhone * const * arrayCopy = new TPhone * [count];
for(int i = 0; i < count; i++) {
arrayCopy[i] = array[i];
}
for(int i = 0; i < count; i++) {
int index = // some function to determine where to place array[i]
array[index] = arrayCopy[i];
}
}
我省略了有关排序算法的细节,因为问题出在其他地方。问题是,声明arrayCopy
.
在线
arrayCopy[i] = array[i]
...
array[index] = arrayCopy[i];
我收到此错误消息
error: assignment of read-only location ‘*(arrayCopy + ((sizetype)(((long unsigned int)i) * 8ul)))’
error: assignment of read-only location ‘*(array + ((sizetype)(((long unsigned int)index) * 8ul)))’
声明中的用法一定有问题,const
但我不知道如何解决它......