On 2007-04-29 16:28, Austin wrote:
Here is my program:
class Test {
private:
int _num;
Try not to use names which start with _, in certain scopes they are
reserved.
};
int main()
{
set<TestaSet;
Test aTest;
aSet.insert(aTest);
return 0;
}
when compiling, vs2003 complain about operator <. If I create a class which
will be used in set, I have to implement or overload operator <? Thanks in
advance.
No you can specify another comparator to use instead, something like
this (untested):
class Test {
int num_
friend bool cmp(const Test&, const Test&);
};
bool cmp(const Test& a, const Test& b)
return a.num_ < b.num_
}
int main()
{
std::set<Test, cmps;
}
But it's usually much easier to just implement operator<.
--
Erik Wikström