Constructor is a special member function of a class that initializes the object of the class. Constructor name is same as class name and it doesn’t have a return type. Lets take a simple example to understand the working of constructor.
Now that we know what is constructor, lets discuss how a constructor is different from member function of the class.
1. Constructor doesn’t have a return type. Member function has a return type.
2. Constructor is automatically called when we create the object of the class. Member function needs to be called explicitly using object of class.
3. When we do not create any constructor in our class, C++ compiler generates a default constructor and insert it into our code. The same does not apply to member functions.