سؤال

I have a custom class and std::vector filled with objects of this class. And I want to do binary_search in this array.

I've overloaded operators on my class like this:

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

and they are working fine (they have bodies, yep).

Now I have an error Error

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

Should I make copy constructor (already overloaded =, but it didn't helped) or add something else to operators?

Thanks.

هل كانت مفيدة؟

المحلول

You need to make the operator const:

bool operator < (const someClass&) const;

without that, only the RHS is const.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top