Topic: STL and less, how to use own class?
Author: "Sami" <Sami.Raatikainen@lut.fi>
Date: 1997/11/13 Raw View
I have a question using less function. What kind of methods, and how, do
you have to define for your class, to use it with less-function???
Shouldn.t "operator<" be enough?
I made my own class "ioValues", and want to use that in map container. So I
have to be able to sort my class' objects. So, I try to use my class with
less, but it doesn't work.
Here's what I have:
class ioValues{
public:
ioValues();
ioValues(const ioValues&);
bool operator==( const ioValues& ) const;
ioValues &operator=( const ioValues& );
bool operator<( const ioValues& );
.....
}
and those methods work just fine
and when I try to make my "own less" in main program:
#include <functional>
#include <map>
#include "ioValues.h"
typedef less<ioValues> _myless;
.....
when I try to compile, I get:
/opt/share/gnu/lib/g++-include/function.h: In method `bool
less<ioValues>::operator ()(const class ioValues &, const class ioValues &)
const':
/opt/share/gnu/lib/g++-include/function.h:112: no match for `operator
<(class ioValues, class ioValues)'
Sami, raatikai@lut.fi
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: "Konstantin Baumann" <kostab@uni-muenster.de>
Date: 1997/11/14 Raw View
Sami wrote:
>
> I have a question using less function. What kind of methods, and how, do
> you have to define for your class, to use it with less-function???
> Shouldn.t "operator<" be enough?
>
> I made my own class "ioValues", and want to use that in map container. So I
> have to be able to sort my class' objects. So, I try to use my class with
> less, but it doesn't work.
> Here's what I have:
>
> class ioValues{
> public:
> ioValues();
> ioValues(const ioValues&);
> bool operator==( const ioValues& ) const;
> ioValues &operator=( const ioValues& );
> bool operator<( const ioValues& );
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This should be a const-method:
bool operator<(const ioValues& ) const;
> .....
> }
>
> and those methods work just fine
> and when I try to make my "own less" in main program:
>
> #include <functional>
> #include <map>
> #include "ioValues.h"
> typedef less<ioValues> _myless;
> .....
>
> when I try to compile, I get:
>
> /opt/share/gnu/lib/g++-include/function.h: In method `bool
> less<ioValues>::operator ()(const class ioValues &, const class ioValues &)
> const':
> /opt/share/gnu/lib/g++-include/function.h:112: no match for `operator
> <(class ioValues, class ioValues)'
--
Konstantin Baumann Westfaelische Wilhelms-Universitaet
Institut fuer Informatik (Zi. 603), Einsteinstr. 62, D-48149 Muenster
mailto:kostab@math.uni-muenster.de Tel:+49-251-83-32701
http://wwwmath.uni-muenster.de/cs/u/kostab/ Fax:+49-251-83-33755
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]