A constructor is a subroutine that returns a new object. An object in this context is a bundle of data that represents an abstraction of something. Some constructors just allocate memory and populate it with default values. Others might register the new object in a master list or other controller object, or could even initialize hardware in the real world.
The opposite is a destructor, which accepts an object and de-allocates it and does anything else needed to maintain class distance of the overall program’s memory. That might include deleting references to the object from elsewhere, or even sending command sequences out to actual hardware.
Latest Answers