Ulrich, I forgot to add that in the derived class the constructor for the
base class must be.
reference can occur.
..
Vladimir Grigoriev wrote:
However try to provide that a + a will not compute when a + b, b + a, and
b + b will compute for two classes when one is derived from another..
Simple, provide these three overloads and no others:
b operator+(a const& l, b const& r);
b operator+(b const& l, a const& r);
b operator+(b const& l, b const& r);
However, I can't think of a reason for this either. Think of this:
b some_b;
a& a_ref = some_b;
a_ref+a_ref; // now what?
struct c: b {...};
c some_c;
b& b_ref = some_c;
b_ref+b_ref; // and here?
Generally, operator+ is something that rather fits for value types. Public
inheritance usually means the type is rather an entity type, which don't
like being treated as a value.
Uli
--
C++ FAQ: http://parashift.com/c++-faq-lite
Sator Laser GmbH
Geschaftsfuhrer: Thorsten Focking, Amtsgericht Hamburg HR B62 932