Copy by Initialization

You can define a copy constructor for a class. If you do not define a copy constructor and one is required, a default copy constructor is defined. If you do not define a copy constructor, and one is not required, a default copy constructor is declared but not defined. If a class has a copy constructor defined, a default copy constructor is not generated.

Copy by initialization is used only in initialization.

You can define a copy constructor for a class with a single argument that is a constant reference to a class type only if all its base classes and members have copy constructors that accept constant arguments. For example:

class B1
{
public:
      B1(const B1&) { /* ... */ }
};


class D: public B1
{
public:
      D(const D&);
};
D::D(const D& dobj):B1(dobj) { /* ... */ }

Otherwise, you can define a copy constructor with a single reference to a class type argument. For example:

class Z
{
public:
      Z(Z&);
};
Z::Z(Z&) { /* ...*/ }

The default copy constructor for a class is a public class member.



Initialization by Constructor
Constructors
Copy by Assignment