P
pauldepstein
A book I have describes a class called vector.
It then explains (and I understand) the concept of a copy constructor,
which is needed to interpret statements like
vector b = a;
But then I get confused when it speaks of overloading =, and explains
that this concept is needed to interpret statements like b = a;
when b and a are vectors.
But didn't we take care of the b = a problem when we set up the
copy constructor?
Why on earth do we need to do the same thing twice (as it appears to
me)?
Apparently, we set up the copy constructor to allow copies of objects
in a class. But, for some unfathomable (to me) reason, this isn't
quite good enough and we need to overload the = operator (again in
order to allow copies of objects in a class.)
Could someone explain the difference between these two concepts, so
that I can see why both the copy constructor and the overloading are
needed?
Thank you,
Paul Epstein
It then explains (and I understand) the concept of a copy constructor,
which is needed to interpret statements like
vector b = a;
But then I get confused when it speaks of overloading =, and explains
that this concept is needed to interpret statements like b = a;
when b and a are vectors.
But didn't we take care of the b = a problem when we set up the
copy constructor?
Why on earth do we need to do the same thing twice (as it appears to
me)?
Apparently, we set up the copy constructor to allow copies of objects
in a class. But, for some unfathomable (to me) reason, this isn't
quite good enough and we need to overload the = operator (again in
order to allow copies of objects in a class.)
Could someone explain the difference between these two concepts, so
that I can see why both the copy constructor and the overloading are
needed?
Thank you,
Paul Epstein