copy constructor

Hi,
When I use a copy constructor for my class for which one of the data members is an array, should I first delete[] *_data and then allocate is with new? The same question refers to operator =.
Your class should delete whatever it allocated in this instance.

In a copy constructor, you generally don't have to delete anything because you haven't allocated anything yet.

In an assignment operator, deleting may be necessary if you need to resize/reallocate the buffer.
Topic archived. No new replies allowed.