2012-06-28 47 views
0

我有一個自定義類和std::vector填充此類的對象。我想在此陣列中執行binary_searchbinary_search()需要的自定義類比較

我重載運算上我的課是這樣的:

bool operator ==(const someClass&); 
bool operator > (const someClass&); 
bool operator < (const someClass&); 

和他們工作的罰款(他們有機構,是的)。

現在我有一個錯誤錯誤

2 error C2678: binary '<' : no operator found which takes a left-hand operand of type 'const someClass' (or there is no acceptable conversion) 

我應該讓拷貝構造函數(已經超負荷=,但它並沒有幫助)或增加經營別的東西嗎?

謝謝。

回答

4

你需要使運營商常量:

bool operator < (const someClass&) const; 

不說,僅是RHS常量。