Default constructor (created automatically)

There are 3 steps in creating an object of class.

  1. Distributing memory space for the object
  2. Initializing member variables using initializer
  3. 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:

Snip20150502_13 Notice there isn’t a constructor. Then, c++ compiler automatically creates a default constructor. So the above example is same as,

Snip20150502_14

Leave a comment