constructor in c++


 Constructor is a special member function its name is same as the class name.

  • The constructor is invoked automatically whenever an object of its associated class is  created.
  • It  is called constructor because it constructs the values of the data member of the class

types of constructor

there are different types of constructor  available in c++.

  1.   Default constructor

 The constructor that accept no parameter is called default constructor.

      2.  parameterized constructor

 The constructor that can take arguments are called parameterized constructor.

Characteristics of constructor

  1.  They should be declared in the public section.
  2. They are invoked automatically when the objects are created.
  3. They do not have  return (data type) type not even void and there for they cannot return any values.
  4. They can not be inherited, the a derived class can call the  base class constructor.
  5.  They make implicit calls to the operator new and delete when memory allocation is required.
Scroll Up