-1

所以我正在处理这段代码,我收到一个错误“二进制表达式'int'到'int *'的无效操作数”我将向您展示我尝试过的测试方法以及我正在尝试的工作这给了我一个错误。

//assume aptr has been declared in a base class
template<class T>
void SortableVector<T>::sortDescending() {    
    for(int x = 0; x < this->arraySize; x++)
        cout << *(this->aptr + x) << ' '; // this line works just fine. 
    //everything beyond this line does not work
    for ( int i = 0; i < this->arraySize; i++)
    {
        for (int j = i+1; j < this->arraySize; j++)
        {
            if ( *(this->aptr + i) < *(this->aptr + j))
            {
                int temporary = *(this->aptr+i);
                *(this->aptr + i) = *(this->aptr + j)
                *(this->aptr + j) = temporary; // here is where the errors appear
                                               // also, it doesn't appear anywhere else
                                               // e.g. on the line above it.
            }
        }
    }
}

拜托,如果有人能告诉我我是否在这里遗漏了什么,我将不胜感激。我正在尝试在 Xcode 中执行此操作,我会尝试“强制运行”它,但我不知道该怎么做,也不知道 Xcode 中的类似功能

4

2 回答 2

1

你忘了 a;在末尾:

*(this->aptr + i) = *(this->aptr + j)

(错误行之前的行)

于 2013-07-14T01:25:11.573 回答
1

这里缺少分号:

*(this->aptr + i) = *(this->aptr + j)
于 2013-07-14T01:27:00.523 回答