最初由 Rabbit 发布
http://www.fredosaurus.com/notes-cpp/oop-condestructors/copyconstructors.html
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 it is somewhat simpler:
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.
最初由 大漠张三 发布
如果我的copy constructor只是 whatever(whatever& a) {}呢?is the default copy constructor still going to make a deep copy?
最初由 西出阳关 发布
C++ uses the default copy constructor only if there is no copy constructor defined for the class. Given that, you have to put sth in {...} because C++ doesn't use the default copy any more in your case.
BTW, the default copy constructor only makes a shallow copy. Don't write a copy constructor if shallow copies are ok for you. In addition, if you need deep copy, you have to write your own copy constructor.
Good luck!