Re: can operators be inherited?
On Aug 1, 6:07 pm, puzzlecracker <ironsel2...@gmail.com> wrote:
On Aug 1, 11:25 am, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
Victor Bazarov wrote:
puzzlecracker wrote:
I don't recall whether operators, which are members of the class, are
intherited in subclasses?
If you meant to ask whether they were inherited, then, yes, they are,
just like any other function.
Correction: except for 'address of', I believe. And keep in mind that
each class has its own operator= that hides any inherited operator=.
What if I make operators virtual in the base class, would they still
be hidden - or according to the standard, operators cannot be
virtual?
As far as the definition goes, a user defined operator is just a
function with a funny name, and it obeys all of the rules of a
function.
A more general comment, however: C++ operators are value
oriented, and values and polymorphism don't really mix very
well. So the presence of a virtual operator is *usually* a
symptom of a design error (although there are one or two
specific idioms, like letter/envelope where it makes sense).
Just because you can do something doesn't mean that you should.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34