[問題] hw1.2.b

看板EE_DSnP作者 (TONY)時間15年前 (2009/03/17 18:45), 編輯推噓5(503)
留言8則, 3人參與, 最新討論串1/1
想請問我有一個err passing `const Compare' as `this' argument of `virtual bool Compare::operator1(int, int)' discards qualifiers 看不懂問題是什麼意思? operator宣告在Compare裡 class Compare{ ... virtual bool operator1(int, int)=0; ... } 錯誤指的位置是在 void selectionSort( vector<int>& array, const Compare& compare) { .... ...... ==> if (!compare.operator(array[pivot], array[j])) pivot = j; ........ } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.4.235

03/17 18:54, , 1F
operator overloading不是這樣用的..
03/17 18:54, 1F

03/17 21:32, , 2F
你那樣寫 "operator1" 會變成一個 member function 的名字
03/17 21:32, 2F

03/17 21:33, , 3F
注意, 是 virtual bool operator() (int, int) = 0;
03/17 21:33, 3F

03/19 21:57, , 4F
我寫的應該是正確的operator overloading但也有這訊息
03/19 21:57, 4F

03/19 21:57, , 5F
那個訊息是什麼意思??y
03/19 21:57, 5F

03/19 22:07, , 6F
把const加上去就過了...const是一種type嗎??
03/19 22:07, 6F

03/19 22:10, , 7F
一個 function 有 const 跟沒有 const 是不一樣,
03/19 22:10, 7F

03/19 22:10, , 8F
這個明天一開始就會講到!
03/19 22:10, 8F
文章代碼(AID): #19ltytOy (EE_DSnP)