[cs23021] note on overloaded assingment

Mikhail Nesterenko mikhail at cs.kent.edu
Wed Mar 28 20:44:07 EDT 2012


CSI students,

Take note, it is better to code the overloaded assignment such that it
returns a reference to the object, rather than the object itself. This
way, the extra constructor and destructor are not invoked on the
returned object. For example, in the 11th lab, the prototype would be:

  varArray& operator=(const varArray&); // overloaded assignment

Note the ampersand in front of the return value.

I have updated the header file in the lab assingment, the slides, and
the example we studied in class located here:

   http://www.cs.kent.edu/~mikhail/classes/csi.s12/Examples/DynamicObjs/Dayschedule.shrinkNgrow/

Thanks,
-- 
Mikhail


More information about the cs23021-2 mailing list