In C++, the copy constructor for a class X is the constructor member function X::X(const X& x). Its job is to create a copy of the object x passed in. Copying is performed when passing objects by value.

Note that the argument of the copy constructor must be passed by reference. The copy constructor is a function; if its argument were passed by value, the compiler would have to call the copy constructor to pass the copy constructor's argument, which would have to call the copy constructor, etc.

For simple objects the default copy constructor supplied by the compiler is good enough. Some authorities recommend writing a copy constructor in any case, but Bjarne Stroustrup recommends against doing so. The copy constructor may be used to implement various kinds of data sharing -- or to prevent Bad Things from happening because of any sharing induced by the default copy constructor.

If you find yourself in need of a copy constructor, remember the rule of three!