Why copy constructor has most basic function to initialize


Assignment task:

1. The object that has to be copied to new object must be previously created. The new object gets initialized with the same values as that of the object mentioned for being copied. The exact copy is made with values.

2. The copy constructor has the most basic function to initialize the members of an object with same values as that of some previously created object. The object must be of same class.

3. The restriction for copy constructor is that it must be used with the object of same class. Even if the classes are exactly same the constructor won't be able to access all the members of another class. Hence we can't use object of another class for initialization.

4. When an object is passed to a function, actually its copy is made in the function. To copy the values, copy constructor is used. Hence the object being passed and object being used in function are different.

5. While returning an object we can use the copy constructor. When we assign the return value to another object of same class then this copy constructor will be used. And all the members will be assigned the same values as that of the object being returned.

6. The compiler provides an implicit copy constructor. It is not mandatory to always create an explicit copy constructor. The values are copied using implicit constructor only.

In the case where dynamic memory allocation is used, the copy constructor definition must be given. The implicit copy constructor is not capable of manipulating

Request for Solution File

Ask an Expert for Answer!!
Other Subject: Why copy constructor has most basic function to initialize
Reference No:- TGS03371610

Expected delivery within 24 Hours