Re: operator=
On Jun 6, 12:18 pm, Lionel B <m...@privacy.net> wrote:
On Fri, 06 Jun 2008 02:37:12 -0700, James Kanze wrote:
In general, assignment and polymorphism don't work well
together, and in general, assignment should be banned in
polymorphic classes.
That's a bit strong, isn't it? Ok, I don't want to assign an
apple to a pear, even if they're both fruit; but might I at
least be allowed to assign an apple to an apple?
In which case, presumably, the client code will be dealing with
apples, there's no polymorphism, and no problem. There's no
fundamental problem with providing assignment in the most
derived class, but there's usually also no real use for it,
since the whole point of having a hierarchy is that the client
code deals only with pointers and references to the base class.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=EF=BF=BDe objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=EF=BF=BDmard, 78210 St.-Cyr-l'=EF=BF=BDcole, France, +33 (0)1 30 2=
3 00 34