我一直在尋找一種有效的解決方案,從C++列表中刪除重複項。從C++列表中刪除重複項
該列表由指針,其具有的屬性ID的類對象的。我想刪除基於該ID的重複項。
我的目的,STL的list的獨特方法,將工作中,我們可以通過一個BinaryPredicate。即
空隙獨特(BinPred PR);
我搜索有關如何使用此方法在互聯網上,正得到中,我們可以聲明函數返回布爾值,並使用該功能作爲二元謂詞的「名稱」的一個例子。
但它不工作。
實際上這是什麼二元謂詞和如何使用它? ... 任何幫助將不勝感激。 這裏是代碼片段:
class SP_MDI_View {
..
..
bool removeDupli(SP_DS_Node*, SP_DS_Node*);
bool DoReductionGSPN(SP_DS_Node*, SP_ListNode*, SP_DS_Node*);
..
..
}
SP_MDI_View::DoReduction(...) {
SP_ListNode setZ; // typedef list<SP_DS_Node*> SP_ListNode, where SP_DS_Node is some other class
setZ.clear();
setZ.merge(tempsubset);
setZ.merge(setX);
setZ.push_back(*cs_iter);
setZ.unique(removeDupli); //Error here
}
bool SP_MDI_View::removeDupli(SP_DS_Node* first, SP_DS_Node* second) {
return ((first->GetId())==(second->GetId()));
}
這是我所說的例子的鏈接: http://www.cplusplus.com/reference/stl/list/unique/ 這是有效的嗎? mylist.unique(same_integral_part); 我的編譯器沒有把它當作一個有效的語句。 – 2010-07-15 23:52:56
你是什麼意思「不工作」?編譯錯誤?段錯誤? – SoapBox 2010-07-15 23:53:48
發佈**你的**代碼,是一個成員函數嗎?範圍是什麼? – 2010-07-16 00:04:21