Copy Constructor
Copy Constructor
Constructor:
1. Constructor are special member functions which allocate memory space for newly created object
2. Beside this the constructor can initialize the member variables of the object
3. Constructor is called automatically by complier at the time creation of some object
4. We can not call constructor explicitly
5. The name of the constructor is same as that of the class
6. By default return type of the constructor is void
Types:
1. System default Constructor:
That can create object but does not assign any values to its attributes is called " System default Constructor"
Can only allocate memory space for newly created object but it can not perform initilialization operation
It is supplied by the complier itself if no user defined constructor is supplied
It can not accept any parameters and arguments
3. Copy Constructor:
It allows us to create an object as an exact copy of some existing object in terms of its attributes
Now if we pass the object of the copy constructor has the call by value method then again copy constructor will be called for that object
Destructor:
Its is a special member function which deallocate memory space allocated to an object by the constructor
Name of the destructor is same as that of the class with ~ (tilda) character prior to it
By default the return type of the destructor is void
Destructor can not take any parameters