作者love20123 (傻瓜)
看板EE_DSnP
標題[問題] hw1.2.p2b
時間Wed Oct 7 18:56:53 2009
照著老師上課的指示
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
1F:推 yangjiunru:bool operator()必須要是const member function才能被 10/07 19:18
2F:→ yangjiunru:const object呼叫 10/07 19:18
3F:→ yangjiunru:可以google一下const member function 10/07 19:19
4F:推 ric2k1:正解 10/07 19:41
5F:→ love20123:感謝強者書豪解決了我的問題 10/07 21:46