D
desktop
I get this error when I run my program:
red_black_tree.cpp:188: error: no matching function for call to
‘std::less<MyObj<int> >::less(MyObj<int>&, MyObj<int>&)’
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_function.h:224:
note: candidates are: std::less<MyObj<int> >::less()
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_function.h:224:
note: std::less<MyObj<int> >::less(const
std::less<MyObj<int> >&)
The code is rather comprehensive so I have just included the code that
causes the error below (where C is std::less as default):
/* used for testing. */
template <typename K, typename V, typename F, typename C, typename A,
typename N, bool B>
typename red_black_tree<K, V, F, C, A, N, B>::iterator
red_black_tree<K, V, F, C, A, N, B>::test_tree(value_type e1, value_type
e2) {
// this does not work!
if (C(e1,e2)) {
std::cout << "here\n";
}
return iterator(parent[(*this).header]);
}
This is the objects that I am trying to compare:
template<typename I>
class MyObj {
public:
MyObj(){}
MyObj(I a) : key(a) {}
I getKey() const {
return key;
}
void setKey(I a) {
key = a;
}
bool operator<(const MyObj& mobj) const {
return (key < mobj.getKey());
}
private:
I key;
};
int main() {
typedef red_black_tree<MyObj> set;
set mySet;
MyObj<int> my1(1);
MyObj<int> my2(2);
mySet.test_tree(my1,my2);
return 0;
}
It seems that less can only be used like:
less()
or
less(const std::less<MyObj<int> >&)
But that is not how I use it or have read that it is supposed to be used.
red_black_tree.cpp:188: error: no matching function for call to
‘std::less<MyObj<int> >::less(MyObj<int>&, MyObj<int>&)’
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_function.h:224:
note: candidates are: std::less<MyObj<int> >::less()
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/stl_function.h:224:
note: std::less<MyObj<int> >::less(const
std::less<MyObj<int> >&)
The code is rather comprehensive so I have just included the code that
causes the error below (where C is std::less as default):
/* used for testing. */
template <typename K, typename V, typename F, typename C, typename A,
typename N, bool B>
typename red_black_tree<K, V, F, C, A, N, B>::iterator
red_black_tree<K, V, F, C, A, N, B>::test_tree(value_type e1, value_type
e2) {
// this does not work!
if (C(e1,e2)) {
std::cout << "here\n";
}
return iterator(parent[(*this).header]);
}
This is the objects that I am trying to compare:
template<typename I>
class MyObj {
public:
MyObj(){}
MyObj(I a) : key(a) {}
I getKey() const {
return key;
}
void setKey(I a) {
key = a;
}
bool operator<(const MyObj& mobj) const {
return (key < mobj.getKey());
}
private:
I key;
};
int main() {
typedef red_black_tree<MyObj> set;
set mySet;
MyObj<int> my1(1);
MyObj<int> my2(2);
mySet.test_tree(my1,my2);
return 0;
}
It seems that less can only be used like:
less()
or
less(const std::less<MyObj<int> >&)
But that is not how I use it or have read that it is supposed to be used.