There are 3 steps in creating an object of class.
- Distributing memory space for the object
- Initializing member variables using initializer
- Running constructor — our topic
An object is created after a call to constructor. In other words, the constructor must be called to create an object (instance). To prevent the case programmer does not create a constructor, the c++ compiler automatically creates “default constructor”.
* Default constructor does not have any parameters, it does not return anything. It is not void though.
If you create a class that looks like this:
Notice there isn’t a constructor. Then, c++ compiler automatically creates a default constructor. So the above example is same as,