patmorin / ods

Mission: To provide a high-quality open content data structures textbook that is both mathematically rigorous and provides complete implementations.
http://opendatastructures.org/
Other
1.2k stars 250 forks source link

I think it is better to make it deep copy. #65

Open BruceWayneLinxu opened 6 years ago

BruceWayneLinxu commented 6 years ago

// https://github.com/patmorin/ods/blob/master/cpp/array.h array& operator=(array &b) { if (a != NULL) delete[] a; a = b.a; b.a = NULL; length = b.length; return *this; } a = b.a; // This is not deep copy.

tekinozbek commented 6 years ago

I would agree, especially since we have move semantics now. That function could just be refactored into array& operator=(array&& b). Not sure how this works in the context of the book though; it might be worth staying consistent with what Java is doing, since that's the original language used in the book.