Constructor with Default Arguments | C++ Tutorial | Mr. Kishore

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi welcome to narrating this is Kishore and today we are going to discuss about constructors with the default organizers okay already in general topic we have discussed that how to send the default arguments with the functions actually in sleep this list there is a concept called functions with the default argument that means without passing all the parameters to the functions we can design a function it is possible in C++ okay generally function is having arguments or parameters and in C language whenever you are declaring a function with a certain argument you should have to pass all the arguments at the time of function calling okay here the major important thing is the function declaration definition calling should be identical for example I have declared one function with the two arguments at calling compulsorily I have to provide all the two arguments okay now it is mandatory to avoid this problem in C++ they have introduced to the concept of functions with default arguments in this concept what happens we are declaring the function with the default values okay whenever the function is declared we are sending some values to the parameters now what happens in function calling whenever the arguments are missing they are going to replace with the defined values which is called functions with the default arguments concept now the same thing is implemented for constructors also that is why we can write the Constructors by using default arguments now how this one is working I will show you with one practical example first of all common example here header files okay now we are going to declare the I was stream rod H as usual corner or H next now the class is taught classes suppose test okay here I want to declare two data members a comma B now Eddie's eighth lecture suppose I want to declare one more also ABC now what happens if the program is what constructors with the default arguments now constructor should be declared in public area the so in public area first we need a constructor that's why constructor main rule is what the function name and class name should be identical that's why first to define a function like this now test class name function in same now it is a constructor and Here I am going to declare some almond int X equal to ten int y equal to 20 and int Z equal to 30 okay generally they are called what arguments or parameters but here the argument is already having some values ten twenty thirty now it is called function with the default argument what we are carrying with to the constructor plus y now it is a constructor with the default order and okay well now here I am going to write like this a equal to X be equal to Y and C equal to Jade now what happened x value 10 passes into a y value 20 passes into be jet value 30 passes into see when the values are not supplied in function calling okay now I will show that one else and now it is called constructor with the default parameters okay now I want to show this data for that another function wide show now here I am going to write C out a equal to otherwise directly I am going to bring the a value next space B value space C value and now in this line what happens for see a value printed later space later B value and later space later C next line and now here the Class E is completed okay now the class is defined on three data members are declared and here the constructor with the default parameters and it is the show function now I have to invoke I have to call the function now it is the main function in main function first of all we have to define the object that's why here I'm going to do like this first to CLRS here okay screen content clear let us see this class name is what test and here it is a constructed and when the constructor is executed when the class object is defined okay when the object of that class is defined automatically constructor now it is the class and here T one okay of 1 comma 2 comma 3 now in which type of constructor parameter is reconstructed okay already it is a constructor which is having arguments now constructor with arguments is called what parameterised constructor that is why here what happened test T 1 and we are sending arguments now the 1 is received by X but already X is having what Tanana now this 10 replace it with 1 on 20 replace riveted to 30 replace it with 3 that means now the default values are overwritten with one two three now one is possible to a two is positive B 3 is positive C okay thus I hear what happened T 1 object created and here three data numbers a value becomes one way value becomes 2 and C value becomes 3 okay five later watch this test another object t2 for example t2 now in bracket I am sending only one two okay actually when this constructor is defined how many arguments will have to send three arguments but here I am standing only one two means two arguments now what happens one is going to replace the x value and two is going to replace the Y value but there is no corresponding value for Jade when it is there is no corresponding value means what happens judge value remaining 30 now Jade value becomes 30 under 30 stored in C that's what happens when t2 object is defined okay it is the t2 object and here a value becomes 1 next behavior becomes 2 but there is no value for C now the C is replaced with Jade that is already having 30 that is why C value 30 that's it next this time Kristof tested t3 of only one now what happened one is going to X X value becomes 1 1 is positive a and BC replace rate the 20 and 30 that's why now - III object also created and here a becomes 1 B value becomes 20 C value becomes 30 now it is the third object ok beside a value becomes 4 B value 2008 30 because of we are not passing any value here that's what we are automatically replaced with default values next now the fourth argument now fourth object test T food there is no argument finish here only the object is created but we are not passing any argument now what happens there is an argument thus I excel 20 and y-value 2021 Generalitat existent by 2030 they are possible to ABC that is why here what happens T for objects Vegeta a value becomes 10 B really becomes 20 and C value becomes a key now total how many objects are defined for objects one is having all the arguments another one is wrong only two arguments third one is having only one and fourth one is not having any argument but there is no error at all because of the missing arguments are replaced with to the default values and it is called functions with default argument are here constructor is force-feeding now website is called constructor with the default argument next I want to show the result that is why here I am going to write like this now p1 dot show what show is going to pin to the a value B value serial enough plus I hear a value 1 2 3 point 8 now answer 1 2 3 it gives the answer line and t2 dot show now t2 data is painted answer 1 to 30 and t3 dot show now it is going to print one okay 20 cutting on p4 dot show on t4 dot so is what 10 20 30 that's what your output is looking like this okay now t1 value is T 2 value speed really for well now get CH program completed it is constructor with default arguments okay thank you for watching in this session we are going for the remaining [Music]
Info
Channel: Naresh i Technologies
Views: 33,475
Rating: undefined out of 5
Keywords: Constructor with Default Arguments, Constructor, Arguments, C++, C++ Tutorial, Kishore, Naresh IT
Id: eQ9jj76eaqk
Channel Id: undefined
Length: 11min 0sec (660 seconds)
Published: Thu Apr 13 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.