Re: STL list Problems
* Mike Copeland:
I'm getting more and more confused about working with STL containers:
everything I try seems to produce a new compiler diagnostic. Here's the
latest (and simplest) thing I've tried to do:
struct TEST
Don't use all uppercase names except for idiomatic usage and macros.
For macros do use all uppercase names.
See the various FAQs on the net about this issue.
{
int num;
int count;
string str;
bool operator==(const TEST &l, const TEST &r) const
{
return l.num == r.num;
}
} testWork;
The compiler produces "C:\CPP\source\list21.cpp(40) : error C2804:
binary 'operator ==' has too many parameters" -I am totally puzzled
about what this means...and why.
Consider how to call your operator:
TEST a, b, c;
if( a.operator==( b, c ) ) { ... }
What does the 'a' object have to do with comparing 'b' and 'c', why is the 'a'
object there at all?
But you have specified that there must be some such object, because your
'operator==' is a non-static member routine.
I am _trying_ to create a small structure to be used in an STL list
(e.g. list<TEST>) that I could sort and change values. The first step
(I thought) was to define an operator that would support "find", but I
can't get anything to compile.
I'd appreciate some guidance on how to get going on this task (the
"find", changing object elements, etc.).
Off the cuff,
struct Foo
{
int asd;
int qwe;
};
bool operator<( Foo const& a, Foo const& b )
{
return (a.asd < b.asd) || (a.asd == b.asd && a.qwe < b.qwe);
}
bool operator==( Foo const& a, Foo const& b )
{
return (a.asd == b.asd && a.qwe == b.qwe);
}
Cheers & hth.,
- Alf
--
Due to hosting requirements I need visits to [http://alfps.izfree.com/].
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!