I am a little stuck with implementing a simple cache and would
appreciate a little help.
I defined a simple map:
typedef boost::bimap<int, yoda::Base> Cache;
Cache cache;
where I am trying to store two different (!) from Base inherited classes.
AFAIK the map requires the less operator to be implemented.
I declared a virtual operator in my Base class:
class Base {
public:
virtual bool operator<(const Base& b) const;
...};
and implemented the operator in the derived classes:
class Tst: public Base {
public:
bool operator<(const Tst& t) const; // less then
private:
std::string rep;
...};
bool Tst::operator<(const Tst& t) const
{
return (this->rep < t.rep );
}
The compiler throws me:
/usr/local/include/boost/bimap/bimap.hpp:156: instantiated from
‘boost::bimaps::bimap<int, yoda::Base, mpl_::na, mpl_::na, mpl_::na>’
maptest.cpp:20: instantiated from here
/usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/bits/stl_function.h:230:
error: no match for ‘operator<’ in ‘__x < __y’
make: *** [maptest.o] Error 1
I am not sure where my mistake lies. Is it the virtual operator?
How else would I implement a cache to store different objects?
Thank you for any advice,
-- Bernd