A copy constructor is a special constructor in the C++ programming language for creating a new object as a copy of an existing object. The first argument of such a constructor is a reference to an object of the same type as is being constructed (const or non-const), which might be followed by parameters of any type (all having default values).
Normally the compiler automatically creates a copy constructor for each class (known as a default copy constructor) but for special cases the programmer creates the copy constructor, known as a user-defined copy constructor. In such cases, the compiler does not create one. Hence, there is always one copy constructor that is either defined by the user or by the system.
A user-defined copy constructor is generally needed when an object owns pointers or non-shareable references, such as to a file, in which case a destructor and an assignment operator should also be written (see Rule of three).
Read more about Copy Constructor: Definition, Operation, Bitwise Copy Constructor, Logical Copy Constructor, Explicit Copy Constructor
Famous quotes containing the word copy:
“Matisse makes a drawing, then he makes a copy of it. He recopies it five times, ten times, always clarifying the line. Hes convinced that the last, the most stripped down, is the best, the purest, the definitive one; and in fact, most of the time, it was the first. In drawing, nothing is better than the first attempt.”
—Pablo Picasso (18811973)