Xcode运行到C ++指针错误

时间:2013-07-14 01:23:27

标签: c++ templates pointers this

所以我正在处理这段代码而且我得到一个错误“二进制表达式'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中的这样的功能

2 个答案:

答案 0 :(得分:1)

你忘记了;的结尾:

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

(错误行之前的行)

答案 1 :(得分:1)

这里缺少分号:

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