E
ek
I have the following class:
template<typename I>
class test {
public:
test(I i) : pp(i) {}
I getpp() const {
return pp;
}
void setpp(I i) {
pp = i;
}
bool operator<(const test& t) const {
return (this < &t);
}
private:
I pp;
};
In main I do:
int main(){
test<int> t1(1);
test<int> t2(2);
std::less<test<int> > C;
std::cout << "C(t1,t2) = " << C(t1,t2) << std::endl;
std::cout << "C(t1,t1) = " << C(t1,t1) << std::endl;
return 0
}
But it prints 0 in both cases. How do I compare objects? When I supply
these objects to a std::set the '<' operator in my class should work
so at the moment the tree would not be balanced correctly.
Another thing. I don't see the point in using 'C' I can just use the
operator '<' directly:
std::cout << "t1 < t2 = " << (t1 < t2) << std::endl;
std::cout << "t1 < t1 = " << (t1 < t1) << std::endl;
which gives the same result, so why go through the extra layer with
using std::less which just calls the '<' anyway instead of just
calling '<' directly?
template<typename I>
class test {
public:
test(I i) : pp(i) {}
I getpp() const {
return pp;
}
void setpp(I i) {
pp = i;
}
bool operator<(const test& t) const {
return (this < &t);
}
private:
I pp;
};
In main I do:
int main(){
test<int> t1(1);
test<int> t2(2);
std::less<test<int> > C;
std::cout << "C(t1,t2) = " << C(t1,t2) << std::endl;
std::cout << "C(t1,t1) = " << C(t1,t1) << std::endl;
return 0
}
But it prints 0 in both cases. How do I compare objects? When I supply
these objects to a std::set the '<' operator in my class should work
so at the moment the tree would not be balanced correctly.
Another thing. I don't see the point in using 'C' I can just use the
operator '<' directly:
std::cout << "t1 < t2 = " << (t1 < t2) << std::endl;
std::cout << "t1 < t1 = " << (t1 < t1) << std::endl;
which gives the same result, so why go through the extra layer with
using std::less which just calls the '<' anyway instead of just
calling '<' directly?