cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
copy constructor
copy constructor
Aug 5, 2011 at 6:40pm UTC
gizzmo
(54)
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
=
.
Aug 5, 2011 at 6:43pm UTC
Disch
(13742)
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.