Constructors and destructors are provisions for initialization and cleanup of objects.
A constructor is a special member function with the same name as the Class. It is invoked
automatically when the object is created. It usually contains initialization code for member variables
and allocation of memory. There can be multiple overloaded constructors, with different input
arguments, used to initialize the object in a variety of ways.
A destructor is a special member function that is called just before an object is destroyed. For
example, when the object variable goes out of scope. It is used to perform cleanup. There can be
only one destructor. Its name is ‘~’ followed by the class name.
A constructor is a special member function with the same name as the Class. It is invoked
automatically when the object is created. It usually contains initialization code for member variables
and allocation of memory. There can be multiple overloaded constructors, with different input
arguments, used to initialize the object in a variety of ways.
A destructor is a special member function that is called just before an object is destroyed. For
example, when the object variable goes out of scope. It is used to perform cleanup. There can be
only one destructor. Its name is ‘~’ followed by the class name.
Comments
Post a Comment
https://gengwg.blogspot.com/