Constructors in Object Oriented Programming:
It is convenient if an object can initialize itself when it is first created, without the need to make a separate call to its member functions. C++ provides a non-static member function called as the constructor that is automatically called when the object is created. After objects are created, their members can be initialized by using constructors.
Important points to be noted while using constructors:
1. Constructor name must be the same as that of its class name to which it belongs.
2. Constructors have invoked automatically when objects are created.
3. Constructors cannot specify return types nor return values.
4. Constructors cannot be declared static or const.
5. Constructors should have public access within the class.
Destructors:
A destructor is a member function that is called automatically when an object is destroyed.
~class name ();
Where the class name is the name of the destructor and is preceded by a tilde (~) symbol.
Thanks
Mukesh Rajput
Post A Comment:
0 comments: