Home / Object Oriented Programming / Define constructor and write rules of constructor

Define constructor and write rules of constructor

Define constructor

A constructor is a special type of member function that initializes an object automatically when it is created.

Rules:

  • The name of the constructors must be the same name as class name.
  • Constructor does not have return type.
  • It can be overloaded.
  • Constructor cannot be virtual.
  • Constructor cannot be inherited.
  • It must be public type.