Friday, July 20, 2012

What is the difference between copy constructor and assignment?


A copy constructor is used to initialize a newly declared variable from an existing variable. This makes a deep copy like assignment, but the basic difference are as follows :
  1. There is no need to test to see if it is being initialized from itself.
  2. There is no need to clean up (eg, delete) an existing value (there is none).
  3. A reference to itself is not returned.

No comments :