stacy@csdpie.dec.com (01/13/89)
In a recent article, Dominic Samperi writes: > The C++ program below seems to indicate that the generic vector library > (the one requiring vector.h) contains a bug. I may be using the library > incorrectly, since it really isn't documented anywhere. The comments > at the beginning of the program describe the bug, and also point out > that the bug goes away when a hand-made vector package is used. The problem appears to be in the macro vectorimplement in vector.h(xx). The operator= member function copies the parameter's elements into this's elements, but then deletes the array of elements v; although assignment member functions sometimes legitimately delete such arrays, they legitimately do this only when they also allocate (and set the values of) new ones. Since vector's operator= already requires that the parameter vector be of a length equal to this's, no new allocation appears necessary, hence no deletion appears necessary. Commenting out the line (/* delete[i] v; */) in that member function in that macro (line 55 in my vector.hxx) makes the problem disappear. BTW, the variable i in that line apparently will have the value -1, not the original size of the array. Did I miss the reason why the deletion was there? Webb Stacy Softron, Inc. Waltham, MA currently at: stacy%keeper.DEC@decwrl.dec.com Digital Equipment Corp. Marlboro, MA