我正在使用multiset來存儲訂購對象的集合,我使用運算符<來建立順序標準,但我做錯了什麼,因爲當我通過multiset遍歷打印跟蹤時,我可以看到他們是不是在所有訂購....我真的阻止這個問題...STL multiset設置插入順序C++
我儘量簡化這裏我的代碼:
class CellSearch
{
public:
bool operator<(const CellSearch & C) const;
int getF() const { return _G + _H; }
private:
int _G;
int _H;
}
...
bool CellSearch::operator< (const CellSearch& C) const
{
return (this->getF() < C.getF());
}
我宣佈多重集的方式是:
std::multiset<CellSearch*> myOpenList;
我插入一個新元素是這樣的:
....
CellSearch *actualSearch = new CellSearch(start);
addOpenList(actualSearch, myOpenList);
這裏是功能:
void Grid::addOpenList(CellSearch* actual, std::multiset<CellSearch*>& openList)
{
openList.insert(actual);
}
是我第一次使用多集...其實我不是一個向量第一容器:)你可以在這裏看到錯誤嗎?
我試圖總結代碼,希望不要太多......
謝謝你的建議! :)無論如何,請你舉一個例子來說明怎樣才能比較取消引用指針來比較對象? – Breikdans
@Breikdans - 完成了,但我真的反對它。 – SergeyA
非常感謝!我會考慮不要存儲指針的選項,但是mw學習如何比較指向指針的方法非常有趣:) – Breikdans