D
desktop
I have this class:
class test {
public:
int getpp()
{
return pp;
}
void setpp(int i) {
pp = i;
}
private:
int pp;
};
Now I would like to insert it into a set:
std::set<test, std::less<test> > my_set;
test t1;
my_set.insert(t1);
This does not work (missing a '<' operator) so I add the following to test:
class test {
public:
int getpp()
{
return pp;
}
void setpp(int i) {
pp = i;
}
bool operator <(test const& t) const {
return (*this).getpp() < t.getpp();
}
private:
int pp;
};
Which does not work either.
std::less implements something like:
bool operator() (T const& x, T const& y) const {
return x < y;
}
So I don't quite see why I need to define '<' in 'test' when I supply
std::less<test> to my_set. It seems like double work. What is wrong in
the body of:
test:perator<(test const& t) const
class test {
public:
int getpp()
{
return pp;
}
void setpp(int i) {
pp = i;
}
private:
int pp;
};
Now I would like to insert it into a set:
std::set<test, std::less<test> > my_set;
test t1;
my_set.insert(t1);
This does not work (missing a '<' operator) so I add the following to test:
class test {
public:
int getpp()
{
return pp;
}
void setpp(int i) {
pp = i;
}
bool operator <(test const& t) const {
return (*this).getpp() < t.getpp();
}
private:
int pp;
};
Which does not work either.
std::less implements something like:
bool operator() (T const& x, T const& y) const {
return x < y;
}
So I don't quite see why I need to define '<' in 'test' when I supply
std::less<test> to my_set. It seems like double work. What is wrong in
the body of:
test:perator<(test const& t) const