< overload, references and maps
Hello all,
Code:
class KrakenDimension{
public:
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
KrakenDimensionType type;
int number;
-- snip --
}
bool operator < (KrakenDimension a, KrakenDimension b){
if(a.type < b.type)
return true;
else if (a.type > b.type)
return false;
else
return a.number < b.number;
}
Now, it works fine and well (like you can do a < b) normally,
but why does it stop working when I change the type signature of the comparison operator to:
Code:
bool operator < (KrakenDimension & a, KrakenDimension & b){
?
Not that it doesn't stop working all of a sudden, but it stops working with this:
Code:
map<KrakenDimension, int> themap;
just the declaration itself causes a compiler error (please brace for the long and cryptic message):
Code:
c:/dev-c++/include/c++/3.3.1/bits/stl_function.h: In member function `bool
std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp =
KrakenDimension]':
c:/dev-c++/include/c++/3.3.1/bits/stl_tree.h:1323: instantiated from `std::_Rb_tree_iterator<_Val, _Val&, _Val*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::lower_bound(const _Key&) [with _Key = KrakenDimension, _Val = std::pair<const KrakenDimension, int>, _KeyOfValue = std::_Select1st<std::pair<const KrakenDimension, int> >, _Compare = std::less<KrakenDimension>, _Alloc = std::allocator<std::pair<const KrakenDimension, int> >]'
c:/dev-c++/include/c++/3.3.1/bits/stl_map.h:508: instantiated from `typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, _Alloc>::iterator std::map<_Key, _Tp, _Compare, _Alloc>::lower_bound(const _Key&) [with _Key = KrakenDimension, _Tp = int, _Compare = std::less<KrakenDimension>, _Alloc = std::allocator<std::pair<const KrakenDimension, int> >]'
c:/dev-c++/include/c++/3.3.1/bits/stl_map.h:316: instantiated from `_Tp& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const _Key&) [with _Key = KrakenDimension, _Tp = int, _Compare = std::less<KrakenDimension>, _Alloc = std::allocator<std::pair<const KrakenDimension, int> >]'
educt-dimension.cc:93: instantiated from here
c:/dev-c++/include/c++/3.3.1/bits/stl_function.h:197: error: no match for
'operator<' in '__x < __y'
educt-dimension.cc:9: error: candidates are: bool operator<(KrakenDimension&,
KrakenDimension&)
So yeah, any ideas anyone? Much thanks in advance