C++ Constructor

tutorial and example
tutorial and example

C++ Constructor and Destructor

Constructor is a special member function whose name is same as the name of class name. Constructor is used to initialize the objects of class. Each time the constructor method is invoked when an object is created. It constructs the values of data member of the class so it is called as constructor.

Constructor declaration and definition

When an object of class is created it automatically initializes the data member inside constructor definition. For example the statement:

create object of class as well as initialize the data member.

C++ Types of Constructor

Constructor is categories into different types. These are:

  1. Default constructor
  2. Parameterize constructor
  3. Copy constructor
  4. Dynamic constructor