mat@zeus.opt-sci.arizona.edu (Mat Watson) (11/16/89)
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