看板 EE_DSnP 關於我們 聯絡資訊
照著老師上課的指示 class Compare { ... virtual bool operator()(int,int)=0; }; class Less : public Compare { bool operator()(int i, int j){ ... } }; void selectionSort(vector<int>& array, const Compare& compare) { ... } 可是最後卻出現了兩行錯誤訊息 1. In function 『void selectionSort(std::vector<int>, std::allocator<int> >&, const Compare&)』 2. 錯誤:將『const Compare』做為『virtual bool Compare::operator() (int,int)』的『this』引數時丟棄了類型限定 DEBUG了好久 還是不知道怎麼辦 最後決定吃飯去 希望老師或強者可以解惑一下 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.4.235
yangjiunru:bool operator()必須要是const member function才能被 10/07 19:18
yangjiunru:const object呼叫 10/07 19:18
yangjiunru:可以google一下const member function 10/07 19:19
ric2k1:正解 10/07 19:41
love20123:感謝強者書豪解決了我的問題 10/07 21:46