Aug 17, 2008 at 9:00pm UTC
Hi,
I'm trying to learn to use the built-in sorting algorithm to sort vectors. I've successfully used sort for vectors of ints, floats, and so on. Now I'm trying to sort a vector of instances of a struct I created. The relevant code:
struct binary_board_state {
...
inline bool operator > (binary_board_state b2) { ...
inline bool operator < (binary_board_state b2) { ...
}
vector<binary_board_state> start;
sort( start.begin(), start.end() );
The < and > operators work properly, I've used them many times without problems. However, when I try to build, I get five near-identical errors:
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/stl_algo.h:90: error: passing 'const binary_board_state' as 'this' argument of 'bool binary_board_state::operator<(binary_board_state)' discards qualifiers
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/stl_algo.h:91: error: passing 'const binary_board_state' as 'this' argument of 'bool binary_board_state::operator<(binary_board_state)' discards qualifiers
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/stl_algo.h:93: error: passing 'const binary_board_state' as 'this' argument of 'bool binary_board_state::operator<(binary_board_state)' discards qualifiers
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/stl_algo.h:97: error: passing 'const binary_board_state' as 'this' argument of 'bool binary_board_state::operator<(binary_board_state)' discards qualifiers
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/c++/4.0.0/bits/stl_algo.h:99: error: passing 'const binary_board_state' as 'this' argument of 'bool binary_board_state::operator<(binary_board_state)' discards qualifiers
I have no idea what these mean. Can someone else make sense of this?
Thanks in advance.
Aug 17, 2008 at 10:26pm UTC
It works perfectly now. Thank you, Duoas.