I guess I could just write a function to perform the copy but then that would require me to have to know which classes contain dynamic vectors to prevent me from casually using the assignment operator (=) by accident. This seems like it would become cumbersome, especially in situations where my dynamic array is hidden a few structs deep:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | struct Thing0 { DynamArray arr{}; } struct Thing1 { Thing0 thing0; } struct Thing2 { Thing1 thing1; } Thing2 thing; Thing2 otherThing = thing; //oops! shallow copy performed! //Needed to do this instead Thing2 otherThing; CopyThing(&otherThing, thing); |
Also, what about functions? With no copy constructor function parameters would automatically perform a shallow copy which could cause more bugs for me in the future.