InterviewSolution
| 1. |
What Is "copy Constructor" And When It Is Called? |
|
Answer» Copy constructor is a special constructor of a class which is used to create copy of an object. Compiler will give a default copy constructor if you don't DEFINE ONE. This IMPLICIT constructor will copy all the members of source object to target object. Implicit copy constructors are not recommended, because if the source object contains pointers they will be COPIED to target object, and it may cause HEAP corruption when both the objects with pointers referring to the same location. Copy constructor is a special constructor of a class which is used to create copy of an object. Compiler will give a default copy constructor if you don't define one. This implicit constructor will copy all the members of source object to target object. Implicit copy constructors are not recommended, because if the source object contains pointers they will be copied to target object, and it may cause heap corruption when both the objects with pointers referring to the same location. |
|