Re: Boost and multi-level inheritance
on Wed Aug 29 2007, Marcin Gil <marcin.gil-AT-NOSPAMgmail.com> wrote:
class LessThan
{
public:
virtual bool operator<(const LessThan&) const;
}
and then
class A: public LessThan
{
public:
virtual bool operator<(const A&) const;
}
class B: public LessThan
{
public:
virtual bool operator<(const B&) const;
}
And if I have
A a; B b1, b2; LessThan& ltb1 = b1, <b2 = b2, <a = a;
and
lta < ltb1 - should fall back to LessThan::operator<()
since b is not convertible to a but both are LessThan;
You need to add
using LessThan::operator<;
to the bodies of A and B, and that will work.
ltb1 < ltb2 - should call B::operator<()
in that case you need to override
operator<(LessThan const&) const
^^^^^^^^^^^^^^^
in B.
I would also like to force implementation of operator< and operator==
in all classes derived from LessThan.
They all inherit a public operator< from LessThan. Make it pure
virtual if you want to force it to be implemented.
What would you like operator== to do?
So I thought that either LessThen should be a template (and this
would give no common operator<() ) or I should also use boost for
the ease of work.
I'm not sure boost the operators library can help you until you have a
clearer idea of what you need.
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
The Astoria Seminar ==> http://www.astoriaseminar.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]