Re: Operator problem with std::pair
On Sep 26, 2:54 pm, "Leo Meyer" <leome...@gmx.de> wrote:
if I don't describe this problem properly, please ask me, I'm
not an expert on the STL. This thing has me quite baffled.
I'm porting a program to Pocket PC 2002 using STLPort using MS
EVC3 and I keep running into this problem:
...\STLport-5.2.1\stlport\stl/_algobase.c(198) : error C2678: binary '==' : no operator defined
which takes a left-hand operand of type 'struct stlp_std::pair<class CIMGFile,bool>' (or there is no acceptable conversion)
The problem occurs in an implementation of find:
template <class _InputIter, class _Tp>
_STLP_INLINE_LOOP _InputIter __find(_InputIter __first, _InputIter __last,
const _Tp& __val,
const input_iterator_tag &) {
while (__first != __last && !(*__first == __val)) ++__first;
^ on this line the error is reported
return __first;
}
This is deep in the standard library. The actual error is due
to something incorrect in the call which instantiated this
function. (It could also be a bug in the implementation of the
standard library, but my bets are with an error in your call.)
Could you write a very small program which displays the error,
and post it with all of the error messages?
(If you can, you might also try compiling with a different
compiler/library implementation. The quality of the error
messages varies greatly from one compiler to the next, and it's
possible that the error messages from a different compiler will
be clearer to you.)
As far as I can tell, the pair is being constructed with this
macro call: std::make_pair(CIMGFile(), true)
CIMGFile is a proper class that seems to compile ok.
Previously, in a header file, the programmer defined the ==
operator using:
inline bool operator == (std::pair<CIMGFile, bool> & p, int id )
{
return p.first.GetID() == id;
}
So STLPort keeps telling me that there is no == operator while
there clearly should be. Note that it doesn't work either if I
change std::pair to stlp_std::pair or make it const in the
operator definition. I have also tried "int & id" instead with
no effect. Is there something wrong about the type signature
that I am missing? How can I get this operator definition to
work?
Probably, the first argument of the operator== must be a
reference to const, although if you're passing in non-const
iterators to a standard container, it should still work. Still,
without seeing a concrete example, it's hard to tell.
--
James Kanze