Path: utzoo!censor!geac!jtsv16!uunet!cs.utexas.edu!asuvax!noao!arizona!amethyst!zeus.opt-sci.arizona.edu!mat From: mat@zeus.opt-sci.arizona.edu (Mat Watson) Newsgroups: comp.lang.c++ Subject: Novice question about garbage creation Message-ID: <1191@amethyst.math.arizona.edu> Date: 15 Nov 89 16:31:53 GMT Sender: news@amethyst.math.arizona.edu Distribution: usa Organization: Optical Sciences Center, Tucson, AZ Lines: 34 I have a question about garbage creation in C++. Suppose I define a Simple class that has a constructor, a destructor, an assignment operator, and a friendly operator + like: class Simple { double * vector; // an array of elements int n; // the number of elements in vector public: Simple( int i ) { vector = new double[ i ]; n = i; }; ~Simple() { delete vector; }; Simple & operator = ( Simple & ); // assigns element by element friend Simple operator + ( Simple, Simple); // adds element by element }; Now what I'd like to do inside of main() is have expressions like: Simple result, x, y, z; /* Assume that values have been put into the elements of: * * x.vector, y.vector, and z.vector . */ result = x + y + z; Since the + operator returns an object of the type Simple, does the y + z part of the expression above create an unreferenced object that just sits around and becomes garbage? Thanks in advance. Mat Watson mat@zeus.opt-sci.arizona.edu [128.196.128.219] ..{allegra,cmcl2,hao!noao}!arizona!zeus.opt-sci.arizona.edu!mat Optical Sciences Center, Univ. of Arizona, Tucson, AZ 85721, USA