Through this Blog we are learning about Constructor & Default Constructor ln C++
What is Constructor ?
Constructor is a member function that of a class which initialize the object . In C++ constructor is automatically called when it's object called .
Constructor is different from normal constructor
- Constructor is automatically called when it's object created
- Constructor don't have return type
- Constructor has same name type itself.
Let's us understand the type of constructor in C++ by taking the real life example .
Suppose you went to a shop for buy a Tv , what are the options ? , First you go to the shop and buy a Tv . but here you can not tell that which type of TV you want ( black & white or Colorful ) so here this is same as default constructor , Second you went to the shop and says such parameter like brand name or color so the shopkeeper will give you what you want , this is same as parameterized constructor . Third one ! , You go to the shop and says you buy a Tv like this ( a pyhsical Tv in your hand ) So the shopkeeper will see that Tv . Okay , he will give a new Tv like that so this same as copy constructor .
Default Constructor
Default constructor is a also a type of constructor which doesn't take any argument or does not pass any parameter.
Example :
Parametrized constructor are the those type of constructor which passes arguments that help us to help us to call easily when it's object created .
Example :
Copy constructor is a member function which initialize an object which using another object .
Example :
Output :
p1.x = 10, p1.y = 15
p2.x = 10, p2y = 15
Constructor Video : Click Here
This is my YouTube channel : Click Here
Playlist of C++(Full Course) : Click Here
Playlist of C++(Program ) : Click Here
Please ! write comment if you find anything Incorrect .
This article is contributed by Mohd Abuzar .If you want to share some information please mail at : abuzar.abuzar.mohd325@gmail.com
0 Comments
Do not Comment and any spam text