Copy Constructors and Assignment Operators
One special type of constructor is the copy constructor. It initializes the data members of one object to another object. The object that's used to copy the member's value is passed as an argument to the copy constructor, typically of type reference to the class itself, and possibly const qualified.
The following code refers to a class with a user-defined copy constructor, which copies the data member of the other object into the current one:
class class_name { public: class_name(const class_name& other) : member(other.member){} private: type member; };
A copy constructor is declared implicitly by the compiler when the class definition does not explicitly declare a copy constructor and all the data members have a copy constructor. This implicit copy constructor performs a copy of the class members in the same order of initialization.
Let's look at an example:
struct A { A() {} A(const A& a) { std::cout << "Copy construct...