rendered paste bodyclass ipclass
{
public:
ipclass()
{
host = 0x0;
port = 0;
}
~ipclass() {};
bool operator< (const ipclass& a) { if (host < a.host) return true; else return false;};
Uint32 host; // These are libsdl types
Uint16 port;
};
map<ipclass,netobject*> netobjects;
int main (void)
{
ipclass ip1;
ip1.host = 0x10000FF;
ip1.port = 6780;
ipclass ip2;
ip2.host = 0x100007f;
ip2.port = 6780;
if (ip1 < ip2) printf ("true\n"); else printf ("false\n"); // this works as expected
netobjects.insert (make_pair(ip1,new netobject)); // this line generates the compiler error listed below..
.. etc
entelin@localhost ~/DATA/development/sdlnettest $ make
g++ -Wall -ansi -ggdb -march=athlon-xp -O3 -pipe -lSDL -lSDL_image -lSDL_net -o server server.cpp netobject.cpp
/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/include/g++-v3/bits/stl_function.h: In member function `bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = ipclass]':
/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/include/g++-v3/bits/stl_tree.h:871: instantiated from `std::pair<typename std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::insert_unique(const _Val&) [with _Key = ipclass, _Val = std::pair<const ipclass, netobject*>, _KeyOfValue = std::_Select1st<std::pair<const ipclass, netobject*> >, _Compare = std::less<ipclass>, _Alloc = std::allocator<std::pair<const ipclass, netobject*> >]'
/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/include/g++-v3/bits/stl_map.h:360: instantiated from `std::pair<typename std::_Rb_tree<_Key, std::pair<const _Key, _Tp>, std::_Select1st<std::pair<const _Key, _Tp> >, _Compare, _Alloc>::iterator, bool> std::map<_Key, _Tp, _Compare, _Alloc>::insert(const std::pair<const _Key, _Tp>&) [with _Key = ipclass, _Tp = netobject*, _Compare = std::less<ipclass>, _Alloc = std::allocator<std::pair<const ipclass, netobject*> >]'
server.cpp:50: instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/include/g++-v3/bits/stl_function.h:227: error: passing `const ipclass' as `this' argument of `bool ipclass::operator<(const ipclass&)' discards qualifiers
make: *** [all] Error 1