Path: utzoo!attcan!uunet!jarthur!uci-ics!gateway From: schmidt@crimee.ics.uci.edu (Doug Schmidt) Newsgroups: comp.lang.c++ Subject: Re: assignment Message-ID: <2666CD5A.1964@paris.ics.uci.edu> Date: 1 Jun 90 20:17:31 GMT References: <4628@ethz.UUCP> Reply-To: schmidt@crimee.ics.uci.edu (Doug Schmidt) Organization: University of California, Irvine - Dept of ICS Lines: 42 In-reply-to: tilo@ethz.UUCP (Tilo Levante) In article <4628@ethz.UUCP>, tilo@ethz (Tilo Levante) writes: >I have a problem with the assignment operator in >derived classes. Assume the following two classes: > void operator = ( deriv &d ) > { > ?????? > } >} > >How can I implement the operator =? >(Probably a stupid question, but ...) Here are a couple of ways to do it: ---------------------------------------- void operator= (deriv &d) { // first initialize the base class part using base::operator = *(base *)this = d; k = d.k } ---------------------------------------- or ---------------------------------------- void operator= (deriv &d) { // first initialize the base class part using base::operator = base::operator= (d); k = d.k } ---------------------------------------- Hope that helps! Doug -- A monk asked Kegon, ``How does an enlightened | schmidt@ics.uci.edu (ARPA) one return to the ordinary world?'' Kegon replied, | office: (714) 856-4043 ``A broken mirror never reflects again; fallen flowers never go back to the old branches.''