Whenever an object goes out of scope, it is destroyed. The memory used by that object is reclaimed. Just before the object is destroyed, an object's destructor is called to allow any clean-up to be performed.
A dectructor, as the name suggests, is used to destroy the objects that have been created by a constructor. Like a constructor, the destructor is a member function whose name is the same as the class name but is preceded by a tilde sign(~). For example, the destructor for the class number can be defined as shown below:
~number() { }
A destructor does not take any arguments; LEARN MORE>>
A dectructor, as the name suggests, is used to destroy the objects that have been created by a constructor. Like a constructor, the destructor is a member function whose name is the same as the class name but is preceded by a tilde sign(~). For example, the destructor for the class number can be defined as shown below:
~number() { }
A destructor does not take any arguments; LEARN MORE>>
No comments:
Post a Comment