Constructor In C++ | Constructor Explained With Real Life Example
Constructor In C++ What is a constructor? Constructor sounds like it will construct something, right? So yeah it is somewhat related to construction. So I will ask you a question if you want to stay in your house which is not built till now then what will you do? Maybe you will say what are you asking Dhruv. Well, the answer is very simple you will construct your house first. Am I right?. And you can do any change in your house during the construction right. So as in this example, the house will call class and the process of building your house will call the constructor. So when you create a class or call an object of any class then first before going into class first your class is calling constructor which will run by default but if you want to modify that constructor then you can do it. Constructor is like a simple function that will run every time when we go inside a class. Here is the official definition of a constructor - A constructor is ...