2013-07-14 41 views
-1

所以我正在處理這段代碼,並且我得到一個錯誤「無效的操作數到二進制表達式'int'到'int *'」我會告訴你我試過的測試方法,我試圖去上班,這給了我一個錯誤。Xcode運行到C++指針錯誤

//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中的功能

回答

1

您忘記了;結束:

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

(錯誤行前行)

+0

是我剛纔讀的頭說的xD謝謝了! :d –

1

分號缺少這裏:

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