How can I perform a deep copy with the following code? I have done some research but nothing has helped. I heard that I need to copy it recursively but how can i do that? most posts about deep copies show code similar to what I have so I can't see how the two are any different.
OtherClass<int>* arr = nullptr;
int size = 0;
public:
copyConstructor(const copyConstructor& src){
if (src.arr) {
delete[] arr;
size = src.size;
arr = new OtherClass<int>[size];
for (int i = 0; i < size; i++) {
arr[i] = src.arr[i];
}
}
else {
size = 0;
arr = nullptr;
}
}