Constructors in C++

a constructor in C++ is a special method that is invoked automatically at the time an object of a class is created. It is used to initialize the data members of new objects generally. The constructor in C++ has the same name as the class or structure. It constructs the values i.e. provides data for the object which is why it is known as a constructor.

Syntax of Constructors in C++. The prototype of the constructor looks like this:

class-name (){
...
}