Compiler Error Using Overloaded Operator

I'm attempting to use a hash class that I've developed within an std::map, and despite the fact that I've overloaded operator< I'm receiving the following error:

error C2678: binary '<' : no operator found which takes a left-hand operand of type 'const ore::CEngine_BigHash<bytes,inputType>' (or there is no acceptable conversion)"


I'm using Visual C++ 2010, with the following overloaded operator:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class CEngine_BigHash
{
public:

	...

	bool operator < (const CEngine_BigHash & object)
	{
		for (Type_UnsignedInt16 i = 0; i < myBytesPerHash; i++)
		{
			if (myPtr_RawBytes[i] < object.myPtr_RawBytes[i])
				return true;
		}
		return false;
	}

	...

}
Last edited on
That looks like a global operator, so it needs to take two parameters. Either that or put your class_name:: in front of the operator name, if it is in fact supposed to be a method.
Sorry, I cut out the class since it took up a large chunk of code. I've edited it so that it makes a bit more sense.
Your myPtr_RawBytes is an std::map, correct? If that's so, then, IIRC, you can't use it's operator[] because you have a const reference, and the array subscript allows you to modify the data.
I really need to get better at giving information. This issue isn't coming from within the operator itself, it's from comparing two BigHash objects within an std::map. myPtr_RawBytes is a statically allocated array of chars.
Your operator looks fine then, so it must be a problem with where you are calling it. Could you post a snippet for that part?
I'm not calling it, std::map is calling it:

xfunctional:
1
2
3
4
5
6
7
8
9
template<class _Ty>
	struct less
		: public binary_function<_Ty, _Ty, bool>
	{	// functor for operator<
	bool operator()(const _Ty& _Left, const _Ty& _Right) const
		{	// apply operator< to operands
		return (_Left < _Right);
		}
	};
Your operator needs to be const in the class.
WHAT, I had it const originally and it didn't compile even then... Right, thanks for the help.
No problem. I really should have noticed that immediately, though...
Topic archived. No new replies allowed.