Hey guys, what's up, this is Umar Khan and I welcome you to a new section here on this course on advanced C++ and in this section, we are going to be covering a very interesting topic that is namespace in C++. Now this is basically going to be the content which we are going to be covering in this section. So first we are going to start on with the introduction to namespaces, then we are going to see the relation between classes and namespaces, then we are going to see that how you can basically access a namespace, then we are going to study about nested namespaces, then we are going to see that how you can create an alias name for a namespace and then finally we are going to study about inline namespaces. So if I tell you this is a very important and a very interesting topic and it is a topic that is most often collected by many programmers. So I suggest that you stick on to this section because this is such an important topic in C++ to learn. So thank you so much for now and the next tutorial we are going to start on with the introduction to namespaces. So bye-bye till then. Hey guys, what's up, this is Umar Khan and I welcome you to the very first tutorial on namespaces in C++. So as I told you that in this tutorial we are going to be covering the introduction to namespaces and we are going to be covering some basic examples for how basically this works. So consider a situation when we have for example let's say two persons that have the very same name in the very same class. So whenever we need to differentiate between them definitely we would have to use some additional information along with their name like for example where they live, for example what is their father name, what is their mother name or we are going to add some information that is actually going to distinguish between those two individuals. For example if we have two people that have the name Jack then for example one has the name Jack Reacher and then let's say the second one has the name as let's say Jack Rowe and what we are going to do is that we are going to call one as Reacher let's say and let's say call the other one as Joe. So this is basically some distinction of the second name. So there has to be added some distinction that is to distinguish between those two individuals. So same situation can arise in your C++ applications as well where you have to declare two variables that are going to have the very same name for example one is an integer value and let's say one is a double value then you know that it is going to generate an error. So to solve that error basically C++ has a feature that is name spaces and that is going to solve your error. So if you just move on to the compiler and let me show you that how it is going to generate error. So for example in this main function you have let's say a variable X that is equal to let's say two. So now if you just see out this X it is going to work perfectly fine you know that let's just run it and you can see that it worked perfectly but for example we have a double value that is also from the name X and V let's say declare it to three and then see out X. So now you know that it is going to generate an error as you can see right here that it says conflicting declaration of double X previously declaration as in X. So this is the situation where name spaces come into help and solve such errors. Now in each scope a name can only represent a single entity so there cannot be two variables with the same name in the same scope. So using name spaces what we are going to do is that we are going to create two variables or member function that are going to have the same name. So for example let's just create a namespace right in here let's just remove this stuff from here and let's just write in namespace then you have to write in the name of the namespace you are going to use for example we use the name as W then what we are going to do is that we are going to specify the brackets and in these brackets you can basically define this variable X equal to let's say 10 this time. So now to basically use this int X equal to 10 and you can see that we have this int X equal to 2 because if you run this code you can see right here that it has actually printed out this variable that is the local variable to this main function that is int X equal to 2. So now what if you want to access this int X equal to 10. So what you are going to do is that you are going to see out and then you are going to write the name of the namespace which you are going to access that is named as W and then you are going to specify two columns and then you are going to write in the name of the variable and finally we are going to add a namespace. So if you now just run this code so you can see right here that we have this 10 as well which has been printed from this statement first you have to write the name of the namespace because this is actually the name of the namespace this is a building word and then in writing these brackets you have to actually provide the definition in which you can declare variables or you can do anything else. So basically what's going on in here is that this namespace W has basically rated a new namespace for example if you just consider the very same example of a class what it has done is that it has basically created a new class in which we have one jack here and then one jack is present in this class. So now the conflict is over if you call in this X that is if you call in this jack then this jack is going to reply to you and if you call in this jack that is the local jack basically this is going to reply to you. So if you talk in a more programming sense this int X that is equal to 10 is a part of this namespace and then this int X equal to 2 is a part of this local main function. So if we talk about the definition and creation of namespaces namespaces basically allow us to group named entities that otherwise would have global scope into narrower scopes giving them namespace scopes this allows organizing the elements of a program into different logical scopes referred to by the names. So if you talk some points about what is a namespace basically so first namespace is a feature that is added in only C++ it is not present in the C language. Secondly a namespace is a declarative region that provides a scope to the identifiers that can be names of the type functions variables and anything else inside it. Third multiple namespace blocks with the same name are allowed all declarations within those blocks are declared in the named scope. So basically a namespace definitions begin with the keyword that is namespace as you can see right in here then it is followed by the namespace I think I've just written it on slides as well yes right in here this is the syntax for using your namespaces first you have to write in the building keyword that is namespace then you have to use the name of the namespace which can be anything you can just write in anything you want in here and then you have to write in anything here because this is the scope that is all for the code declaration where x and y are basically declared in the namespace namescope that is whatever is written here. So namespace declarations appear only at global scope namespace declaration can be nested within other namespaces as well moreover namespaces declarations don't have access specifiers that are public or private moreover like right in here if you can see that we have actually now a single namespace that is named as w and then you also have this namespace as well but you can also create multiple namespaces as well for example if I just write in here using the very same syntax that is namespace then you write in the name of the namespace that is let's say y and in here I write in index equal to let's say five so now we have actually three namespaces that is first is this w namespace then this we have this y and then we have this local namespace as well so if you want to access the namespace that is named as y what you're going to do is you're going to write in the name of the namespace then you're going to write the variable you want to print and you're going to write in and that so if you just run it you can see that we have a five here on our output screens as well so this was I guess all about namespaces in C++ introduction you have seen how multiple namespaces can be created in C++ so I guess that's it with this tutorial in the next tutorial we are going to see what is the relation basically between classes and namespaces and how you can actually declare namespaces in the class so that's it with this tutorial thank you so much guys for watching and I'll see you guys in the next tutorial hey guys what's up this is marhan and I welcome you to another tutorial on namespaces in C++ in this tutorial we are going to see the relation between classes and namespace and to elaborate the word relation I actually mean that how we can actually initialize a classes in a namespace how you can only declare a class in a namespace and then give it definition outside this is basically the content we are going to be covering in this tutorial we are going to create classes inside a namespace we are also going to create classes outside the namespace and then we are going to at the very end cover a very small topic that is how you can declare methods outside namespace after actually initializing or declaring them inside so let's move on to our editor because I guess there is nothing much to speak about this stuff so the first thing is that how you can basically declare and initialize and do everything about a class in a namespace so first what you have to do is that you have to create a namespace and let's say the name of the namespace is w and then in this namespace what you have to do is that you have to create a class for example the name of the class is let's say x this is the body of our class and this also has to add a colon at the end and now in this class let's say we have a public method that is let's say white display and what it's going to do is that it's going to simply see out inside the namespace so right here in the main function what we are going to do is that we are going to create an object now how an object for a class within a namespace is going to be created first you have to write in the name of the namespace in this case the name of the namespace is w so you're going to write in w then two columns and then you are going to write in the name of the class that is x then you have to add a space and then you have to write in the object which you want to create and then for example if you want to let's say call this function that is the white display function that must be identified something like this so if you want to call this display function what you have to do is that you have to use this object because now we are into the namespace we have created an object of the class x that is in the namespace w so now what you have to do is that you have to simply write an object dot display and finally if you want to add this statement as well it is very good and now if you just run this code you can see that we have the output that says inside the namespace you so you have seen that how we have actually accessed a class that is inside a namespace now if i just talk about the previous case which we were discussing in the introduction tutorial that we can have multiple variables of the very same name so for example if you want to declare this class x again you can declare it outside the namespace that is class x and then you can do anything right in here for example if you just run this code you are going to see that it is going to run perfectly it is going to generate no error for example let's just create an object of this class as well so just write in x and let's name it as o and let's just run it and you can see right here that it ran perfectly and it generated the same output so you can create actually multiple classes one inside one namespace and one inside another namespace this is actually the global scope this in this case so now to the second part of the tutorial that says that how you can declare a class outside the namespace so for that what you have to do is that you have to first declare the class because we have already this class right in here that is the class x in the global scope so in this global scope you cannot initialize or declare sorry not use another class that is outside so what you have to do is that you have to actually i'll just remove this from here and what you have to do is that you have to write in this class x right in here and let's say we want to give its implementation outside this namespace you can give it but what you have to do is that you are going to write in class then you have to write in the name of the namespace for which this class is going to be defined and then you have to write in the name of the function because if you don't write this thing over here then it is going to generate error because we already have a class x in this global scope now by writing this what you are going to refer is that you are going to refer that this class x belong to basically this namespace and when you don't write this with this class x then you are referring to the global scope that this class belong to the global scope and this belong to the namespace that is named as w so now in here we are going to do the very same stuff that is public and let's say the function is the very same that is the display function and in the body what we are going to do is that we are going to simply see out and now we are going to write in outside the namespace because this implementation has been given outside the name of the namespace that was named as w just going to display and we already have an object to this class let's just run it so you can see it generated the very same output but this time it says outside the namespace because this implementation is done outside the namespace we all we only have declared the class here but the defining of the class is outside the namespace we still have our class x in here in the global scope where we have actually provided the implementation but it is not going to generate error because this class x is in a different scope and this class x is in a different scope now to talk about the last part of this tutorial that how you can actually define methods outside the namespace so if you consider this very same example and let's say we have a function right here that is white display and we have actually only declared that function in over here and then in this class x what we have is that we also have a public method that is white display and also we have not provided an implementation of this class right here in the namespace w as well so now right down here in this class w x or whatever stuff is written in here what we are going to do is that we are going to actually define our method so to define a method of a namespace outside the namespace what you have to do is that first you have to write in white over here then you have to write in the name of the namespace that is w in this case and then you have to just remove it from here and then what you have to do is that you have to write in the name of the class and then you have to write in the name of the function let's just remove it from here all right so I repeat it again first you have to define the return type of the function then you have to write in the name of the namespace to which this function belongs then you have to write in the name of the class to which this function belongs and then you have to write in the name of the function So in this function, you are going to do what you're going to do is that first you are going to just remove this from here, because it is a function now and a colon is not expected at the end. So what you're going to do is that you're going to simply see out, this is the class display function. And now you have another function right in here, that is the void display function also in this namespace that is not in this class. So to define that function, what you have to do is that you are going to gain right in the return type since now we are not dealing with the class function. So we are going to write in only the name of the namespace and then we have to call in the display function. And in this display function, we are going to write in namespace function outside the class. Since this is the name, this is the function of the very same namespace that is named as w, but it is actually outside the class. As you can see right in here, we have two display functions, one is a part of the class that is this function. And we have one more function in this namespace that is named by the very same name, but it is outside this class. So to provide the implementation of this display function that is inside the namespace as well as inside the class, you have to write in and refer to both the namespace and the class as well. But when you are dealing with this display function, that is not inside the class and only inside the namespace, you only have to deal with the namespace and you only have to write in w, call and call and display, and then you can just provide its implementation right in here. Now, in the main function, let's just remove this object, you have seen the purpose of it that it is not going to generate error. So let's just remove it. Now, what you're going to do is that you are going to, in the very same way, create an object of the x class. And then you are going to now call in the display function. Now to call in the display function of the class, sorry, the function that is inside the class where you have to do is that you have to actually use in this object. So you're going to write an object or display the very same way. Now to call the second function that is outside that is the namespace function that is outside the class where you have to do is that you have to write in the name of the namespace. And then you have to simply write in the function which you want to call in. So let's just run it. Yes, we forgot to provide this here at the end. And I've spotted one more error. We forgot to provide the brackets for the function and right here as well. And let's just segment it right down here. And I guess that's perfect. So let's just run it. So as you can see, the first output is that it says this is the class display function. And the second output says that namespace function outside the class. So first the class display function has been has been called because we call it using the object. And then secondly, we call in the function that was only inside the namespace not inside the class. So you have seen now in this tutorial that how you can actually define a class inside and outside the namespace but when you have to declare it outside what you have to do is you have to first declare it inside and then provide its implementation outside that namespace. And secondly, you have also seen that how by only declaring a function inside a namespace, you can access it outside. So we have covered good stuff of examples as well. So I guess that's it with this tutorial. Thank you so much guys for watching and I'll see you guys in the next tutorial. Hey guys, what's up? This is Amir Khan and I welcome you to another tutorial on namespaces in C++. In this tutorial, we are going to see that how you can extend a namespace and how unnamed namespaces are used in C++. So we are going to start on with namespaces having different names and this part have already been covered in the introduction tutorial. Let me just give you a very quick example for how this is implemented. Now I'm talking about the case when we just declared in two namespaces first with the name of W and then we have a namespace with let's say a name of that is of the name by then as you can see right here now we have two namespaces for example we have a variable x that is equal to 10 in this namespace and then we have a variable x that is equal to 2 in this namespace. So if you want to access any of this x for example if you want to access this x that is in this w namespace what you have to do is that you have to write in w and then you have to write in x and in the same way if you want to access the x variable of the y namespace then you have to write in y and call an x. So, this is going to just do your job and if you just write in endel in here and run this code, you can see right here that 10 and 2 are printed in the very same sequence they were called in. So, we have already covered this in very detailed introduction tutorial. So, to move on to the part which we are going to be covering in this tutorial is how you can extend a namespace and how you can basically use unnamed namespaces in C++. So, starting on with extending namespaces. Now, what do I mean by extending namespaces? Extending namespaces mean that using the very same name twice for a very same namespace. Now, let's see for example, we have this let's say namespace w and I also name this namespace to be w as well. So, as you can see right here that we have this namespace w and then this namespace w in which we have the very same variable int x equal to 10 and int x equal to 2. So, if you just run this code, so since these are going to be of the very same namespace, so this scenario is going to generate an error. As you can see right here, it says that it was previously defined here. Now, the purpose to show you this error was that as you can see right here that these have been declared separately. This namespace is declared separately and this namespace is declared separately. But when you use the very same name for a namespace, w it is basically extending a namespace and these two are basically a single namespace that have the name of w. If you use the very same variable int x equal to 10 and int x equal to 2 and write in here what it's going to do is that it's going to simply generate an error message for you. So, you can use here for example, you can use in here y and when you then write in here y and run this code it is going to run perfectly. This is the very same scenario for example, you define int x equal to 10 and then int y equals to 2. So, this is the very same case right in here since as you can see right here that these two that is int x equal to 10 and int y equal to 2 they are in the same namespace that is the local main, local main function these, they have a local scope basically these two variables. So, in this case, this variable x and this variable y also have the very same namespace so they are going to be of the same scope that is named as w. So, I hope it is clear. So, now moving on to unnamed namespaces by unnamed namespaces I means that you do not specify the name of the namespace. Let me just give you a quick example. For example, if I just remove this name from here this is basically calling a namespace that has no name. So, if you just remove this stuff from here and you also remove this from here since it now does not belong to w let's just remove this as well and remove this as well. So, you can see right here that we have a namespace that has got no name and in that namespace we have a variable x that is equal to 10 and in the main function we have c out x without specifying the namespace. So, if you just run it, you can still see that it printed out 10 because it has access to a namespace that is unnamed now. For example, you define a variable x equal to 2 here and now run this code. So, you are going to see that it is now printing 2. Now, why is this stuff going on right in here? Now, if you declare a variable in the scope where you are printing it without specifying the namespace since it does not have a name. So, the priority is going to be for the variable that is declared in that very scope since in this case the c out x statement is actually in this main function that is the that is local for this main function. So, when this int x is declared in this local main function what it's going to do is that it's going to this c out statement is going to give a priority to this int x equal to 2 and print out the value of x as 2. But if it is not present here, then this namespace that is int x equal to 10 is going to be given a priority. Now, what if for example, we have let's say int x equal to 3 right in here in the global scope. So, if you now just run it, it is going to generate an error because this namespace also declared this x equal to 10 as I told you before that in the introduction tutorial that namespaces have a global scope. So, basically, if you don't specify a name here, it is going to be a global scope of this very same namespace in which this program is going on. That is a single namespace for this entire program. But since here it was local, so this x was global and this x is local, that was int x equal to 2, this is local. So, it does not generate an error and it printed out 2 for us. But when you write in int x equal to 3 in the global scope and since this int x equal to 10 is also in the global scope and also it does not have a name, which means that it is a part of this namespace in which this x equal to 3 is present. So, that is the default actually global scope of this program. So, this x equal to 10 is also in the default global scope since it does not have a name. So, this is a contradiction that is x equal to 10 and x equal to 3. So, this statement have to be removed from here. And now if you just comment it out, this statement right in here that is the global, that is the default, I must say default global namespace of this program is going to run and it's going to print out 10 for us. So, I hope it is clear. So, that's it with this tutorial as well. Thank you so much guys for watching and I'll see you guys in the next tutorial. Hey guys, what's up? This is Umar Khan and I welcome you to another tutorial on namespaces in C++. In this tutorial, we are going to be covering about accessing namespace. So, basically there are two ways to access a namespace. The first one is the normal way and then we have a directive way as well. So, let me just give you a quick example of how you can access a namespace by using the normal way, which we have already covered in our previous tutorials. But there, I haven't told you that this is actually the normal way. So, for example, we have a namespace named as A and in this, we have a variable x equal to 10. And now if you just write in C out and first write the name of the namespace, sorry, it is going to be A and then we have to write in this x over here and then and line. So, this is basically the normal way of accessing a namespace. So, if you just run, you know that then it's going to be printed out on your output screens. So, this is basically the normal way of doing it. Now, the second way is by the using directive way. Now, you can actually avoid pre-pending of namespace with the using namespace directive. This directive tells the compiler that the subsequent code is making use of the names in the specified namespace. The namespace is thus implied as let's say a main function that is going to actually direct your code. So how this is going to be done, let's just see an example of this. So, we will define a function in this namespace. Let's name it as white punk. And in this function, what we are going to do is that we are going to simply have a C out statement. And in this, we are going to print out namespace number one, which means that we are also going to add more namespaces. So, outside here, we are going to specify a second namespace. And you don't make you understand this concept. Initializing two namespaces is very essential. And why you're going to just learn in a moment. So, we have the second namespace in which, for example, we have the very same function. And in this, we are going to see out namespace number two. All right, now, if you just move on to this main function, now you know that if you have to call this function, then you have to write in this B and then this colon colon, and then you have to write in punk. And this function is going to be called in. And if you want to call the function that is right here at the top, and you have to write in this A over here. So, for example, we want this thing not to be written here. And if you want to call the function of, let's say, this namespace B by just doing this, then how this is going to be done. This is basically going to be done using. This stuff over here that we were discussing that is using directive way. So, let's just remove it from here. We do not have to specify this C out over here because we have already used the C of statement here. And since it is returning nothing, so C of statement would have generated an error for us. So, what we are going to do right above this main function is that we are going to write in using, which is a built in keyword. Then you have to write in namespace, which is again a built in word. And then you have to write in the name of the namespace for which you want to run this main function. So, I want to run it for this B and then have to specify this over here. And then we have this main function in which we are going to simply call this and this and I'll not hear for sure. And I guess that's it. If you now just run this code, you can see right here that it printed out namespace to because this main function basically now ran for this namespace. If I just specify this A over here, that is the first namespace right here at the top that also has a function that print out namespace number one. So, if you now just run this code, you can see right here that it printed out namespace number one. So, the using directive basically it has directed our main function. So, the using directed can also be used to refer to a particular item within a namespace. For example, if you have, let's say, a variable, let's say we have something like int x equal to 10. Then, since we are dealing with A, let's just make it to B and then C out and then we are going to specify this x right here. That is variable x. So, when we just run this code, you can see that first we have the namespace number two since now we are dealing with the namespace that is B. So, it printed out namespace number two and we have also printed out our variable as well. So, this is how basically you can use the using directive way in C++. You have to just write in, if you talk about the syntax, you have to write in the using keyword, then you have to write in namespace, which is again a building, and then you have to write in the namespace name for which you want to direct this main function. So, in this case, it is directed for this B namespace. So, when the func is called, it is going to call the function that is in this namespace. So, I guess that's it with this tutorial. You now know how to use the using directive way and the normal way to access namespaces. So, thank you so much guys for watching and I'll see you guys in the next tutorial. Hey guys, what's up? This is Omar Khan and I welcome you to another tutorial on namespaces in C++. In this tutorial, we are going to be covering nested namespaces. Now, what does the word nested basically mean? Nested means something inside something. So, nested namespaces means that a namespace that is declared inside a namespace. So, this is basically the syntax for what I am talking. We have this namespace N1 that has its first bracket right in here and this second bracket right in here. And inside this body of the namespace N1, what we have that, we have the declarations of namespace N1 but moreover, we also have a namespace inside this namespace N1 that is named as N2. And in the namespace N2 body, we can have the declarations for the namespace N2. So, now how this is done practically with the help of an example and how we can actually then call the namespace 2 that is actually nested inside the namespace N1. So, let's see how all this stuff is done. So, for example, we have the first namespace as let's say S1 or let's just call it N1. And then we have another namespace that is N2. And in the first namespace, for example, we have a function that print out a simple C out statement for us. That is the outside namespace function. And what this second namespace is going to have is it's also going to have a function that has the type void. And what this is going to do is that it's going to print out. It is the inside function. So, we're going to write an inside namespace function and now this namespace as I told you is going to be nested. So, we are going to just remove it from here. And we are going to paste it right in here. Now, as you can remember from the syntax that we have the namespace N1 and then we have the declarations for namespace S1 as you can see right here. We have the namespace N1, then we have the declarations, then we have the namespace N2 and then it's declarations. The very same which is written right here, namespace N1. Then the declarations that is the function for namespace N1 then we have the namespace N2 that is right. This one over here, this bracket as well. This is the namespace N2 in which we have a function and this is the closing bracket for the nested namespace. So, this is now a nested namespace in which we have this namespace N1 which contains a namespace N2 and both have their functions. Now, if you talk about the main function and let's say for example, you want to call this function that is the nested function, sorry, the function that is the outside namespace function which is not in N2 but is a part of N1. So, to use that using the using directive where what you're going to write and you're going to write in using namespace and as you know that you have to write in the name of the namespace and then this column and then you have to simply write in the name of the function which you want to call. So, if you just run this code now, as you can see right here that it printed out outside namespace function because in this case, we were using the using namespace N1 which was right here at the top that has the function that printed out outside namespace function.  Now, why it is generating errors? Because it says that N2 is not a namespace name because since now N2 is inside the namespace of this N1. So, what we are going to do is that we are going to tell our compiler that N2 is basically inside N1. Now, how we are going to tell him, we are going to write in N1, colon colon N2, which means that N2 is in N1. So, now if you just run it, it's going to print this statement as you can see right here. Now, it says inside namespace function since we have told him that N2 is inside N1 and we have to print out the function. So, it searched for N1, it searched for something and do that is inside N1 and then it searched for this function that is inside N2. So, it printed out inside namespace function. So, this is basically the concept of nested namespaces in C++. So, I guess you have understood it well. So, thank you so much guys for watching and I will see you guys in the next tutorial. Hey guys, what's up? This is Umar Khan and I welcome you to another tutorial on namespaces in C++. In this tutorial, we are going to be covering the topic that is namespace aliasing and it is a very easy topic to understand and basically this thing that is the aliasing of the namespace introduced in this concept because we have to provide some ease to our user. For example, we have a nested namespace in which we have let's say five to six routes. For example, we have a namespace in which we have a namespace and in that namespace we again have a namespace and so on goes until let's say five to six leads. Then what we are going to do is that we are going to provide ease to our user. For example, if you want to access the last namespace that is nested in each and every namespace then to call any function from that namespace it's going to be a very fussy task. So that is where namespace aliasing is going to help us out. So how it is going to be done. Let's see this without. So for example, we have a namespace that is s one and inside that this namespace we have another namespace. Let's say s two in which we have another namespace. Let's say s three in which we have another namespace. Let's say s four and I guess that's enough. So for example, we have a function in this namespace in which we have to simply see out a statement inside the fourth namespace. So as you can see right here that this namespace s four is nested in s three, which is nested in s two, which is nested in s one. So for the main function, for example, we are using the normal way to access the namespace. Then what you have to do basically is that you have to actually write in first s one then you have to write in s two then you have to write in s three then you have to write in s four and then you have to write in funk. So if you just run this code, you can see that it says inside the fourth namespace. So for a single case, I guess that's good. But what for example, we have a variable. Let's say int x equal to 10 in this, then we have a variable int y equals to let's say 20, then we have another variable in z equal to let's say 30 right here in this next state namespace s four. So to use each of these what you have to do every time is that you have to write in s one then s two then s three then s four and then you have to write in X. For example, you want to access the value for X and you have also to add a C out statement for this. So if you just run it, you can simply access the value of X and as well as this function right here at the top as you can see right here is inside the fourth namespace and then it says 10. So now if you want to access this why you have to again write this complete set and for that you have to write in again this complete set and for each and every entry you want to access from this namespace you have to use this. So why not just give this statement right from here to here a name. So then every time we are going to use that name to actually call this namespace. So what we are going to do is that we are going to use the namespace aliasing for this purpose. So right above here where we are going to write in we are going to write in namespace. Then we are going to write an alias name. Let's name it as alias and then what we are going to do is that we are going to write this stuff that is s one then s two then s three and then s four. Add a column here and now whenever you want to use this stuff what you can simply do is that you can just use in this alias keyword and this alias keyword here as well. Let's just run it and you can see that the very same output has been generated as it was in the previous case. So now if you want to get access to the variable why or variable that you can just copy this and paste it over here and you can just change it from here why to that. Now as you can see that the first the task of writing this stuff has been removed and now you can simply write in alias over here. So I guess that was helpful and this is what is the purpose of namespace aliasing in C++ that is to provide ease to the user. So I guess that's it with this tutorial as well. Thank you so much guys for watching and I'll see you guys in the next tutorial. Hey guys. What's up? This is Amir Khan. Now welcome you to another tutorial on namespaces in C++ in this tutorial we are going to see what is basically inline namespaces and inline namespace is basically a namespace that uses the optional keyword inline in its original namespace definition. By using this inline keyword what is the advantage basically is that you don't have to specify the object every time you want to access an element of a nested namespace. For example if we just move on to our compiler and let's say we have a namespace let's say s1 and inside that namespace what we have is that we have an inline namespace that is s2 and in this what we have is that we have let's say a simple variable int x equal to 10 and for example we want to now access this int x equal to 10. So what we can do in this main function that we can just see out s1 and then this x. So if you just run this code you can see that it will run perfectly and you can see right here that 10 has been printed out but if you remember from your previous concept that when you have to use the nested space then you have to write in stuff like you have to write in then s1 and then you have to write in s2 and then this x and then it's going to be printed out but now in case of inline namespaces inline namespaces s2 is going to be treated as it is actually s1 and this variable in x equal to 10 is going to be treated like it is the part of this namespace s1. So as you can see that members of an inline namespaces are treated as if they are the members of the enclosing namespace in many situations. Now this property is transitive if a namespace for example if you have a namespace n and it contains an inline namespace m which in turn contain an inline namespace o then the members of o can be used as though they were the members of m or n. For example we have s2 then we have let's say another namespace in this that is again an inline namespace that is s3 and let's say we have now here a variable int x equal to 10. So just this statement right over here is going to do our job. We just print it out. You can see that 10 has been printed out because this 10 is considered to be a part of like it is a part of this s2 or this s1. You can also use it using this s2 but this is going to now generate error now why? Because s2 is basically inside and not outside. So the compiler does not know that s2 actually exists. So what you have to do is that you have to write an s1 call an s2 and now it is going to run perfectly and it is going to again print out that 10 for us. So this 10 is treated to be like it is a part of s2 and s1 is going to think that it is a part of my. So basically you have also understood one more concept in here that is how an inline space name space can contain another inline name space. So the inline specifier basically makes the declarations from the nested name space and it appear exactly as if they had been declared in the enclosing name space as you have seen in this example. This means that it drags out the declaration from a nested name space to the containing name space. Now what are the advantages of using a name space? There are basically two main advantages of using name spaces. The first one is it avoid the verbose. For example, if you consider this code. And if these were not inline name spaces and you have to access this variable X and what you have to do is that you have to add one more that is s3 and then you have to print it out. Now this looks good only if the name space names are short as in this example we have covered but by using inline what the namespaces there is no need to type the entire namespace as given above or by using the directive method as well. So if you talk about the next part of this tutorial is that how inline namespaces are going to help you out in the using directive inside namespaces. It is going to help you in the very same behavior and it can also be achieved by using the using directive using directive that names the inline namespace is implicitly inserted in the enclosing namespaces. For example, if we consider this very same example in which we have namespace s1 and then inline namespace s2 and then inline space name space s3 and then inline namespace s3 contain a variable index equal to 10 then if you are using the using directive way and you try using namespace and you only have to mention the name of s1 and then this stuff is going to be removed from here and then if you just print out this x and just run this code you can see that it ran and printed out 10 as well. So this was the very same concept in which this s1 thinks that x is a part of it s2 thinks x is a part of it and s3 also thinks x is a part of it. So this makes it actually a single bracket in which this x equal to 10 is contained and you can also print it like this because s2 also thinks that it is a part of it so if you just run it you can see that 10 is again printed and s3 also think it is a part of it so you can write in s3 here as well and run this and again it is going to print out 10 for us. You can see right here. So this was basically the purpose of using inline name spaces in C++ and you have also learned about the advantages of using namespaces sorry inline namespaces and you have also seen how using the normal way and how by using the using directive inside namespaces you can use the inline namespaces and it will help you out. So that's it with this tutorial. Thank you so much guys for watching and I'll see you guys in the next tutorial. Hey guys what's up this is Umar Khan and I welcome you to a new section here on this course on advanced C++ in which we are going to be seeing the new features that are added in C++ 11. So the content covered in this tutorials are basically the additions that are made to C++ 11. These additions are lambda expressions automatic type declaration and declaration type uniform initializations deleted and defaulted functions null pointer delegating constructors or value references and new smart pointer classes. So we are going to be seeing all of these and we'll start on with the introduction tutorial in the next tutorial. So that's it with this tutorial. Thank you so much guys for watching and I will see you guys in the next tutorial. Hey guys what's up this is Umar Khan now welcome you to another tutorial on C++ new features that were added in C++ 11. So this is basically an introduction tutorial in which we will see the introduction to C++ 11 and the features that were added to it. Now from 13 years since the first iteration of the C++ language, Danny Califf that is a former member of the C++ Standards Committee explains how the programming language has been approved and how it can help you write better code. Now Bajanes drops that is the creator of C++ said recently that C++ 11 feels like a new language. The pieces just fit together better. Indeed core C++ has changed significantly. It now supports lambda expressions automatic type deduction of objects, uniform initialization syntax, delegating constructors, deleted and defaulted function declarations, null pointer and most importantly the R value references. That is a new feature that argues a paradigm shift in how one conceives and handles object and that's just a sample we will cover all of these in this section. Now the C++ standard library was also revamped with the new algorithms, new container classes, automatic operations, type traits, regular expressions, new smart pointers, async facilities and a course of multi-threading libraries. Now after the approval of C++ standard in 1998, two committee members prophesied that the next C++ standard would certainly include a built-in garbage collector that is also referred as GC and that it probably would not support multi-threading because of the technical complexities involved in defining a portable threading model. Now 13 years later the new C++ standard that is C++ 11 was completed and guess what it lacks a garbage collector but it does include a state of the art threading library. So from the next tutorial we will start on with the features that will that were included in C++ 11 one by one and after seeing them you will understand yourself that how much useful these features are. So that's it with this tutorial. Thank you so much guys for watching and I'll see you guys in the next tutorial. Hey guys, what's up? This is Umar Khan and I welcome you to another tutorial that discuss about the new features that were added in C++ 11 and in this tutorial we are going to be discussing the very first feature that is lambda expressions. So a lambda expression basically let you define functions locally at the place of the call here by eliminating much of the TDM and security risks that function objects incur or maybe they want to search for all email addresses that also show up in another list now there are a lot of potentially interesting things to search for instead of building all of these options into the class wouldn't it be nice to provide a generate find method that takes a procedure for defining if an email address is interesting or not. Now to talk about the syntax of using lambda expressions you can see it right on your screens. First we have to define the captures then we have to define the parameters then the return types declaration and in the body we will have our lambda statements. Now to elaborate further you talk about capture the capture clause is also known as the lambda introducer and it specifies which outside variables are available for the lambda function and whether they should be captured by value or by reference. You will also be able to identify the start of a lambda expression with the presence of the capture clause and an empty capture clause means capture nothing in which case the lambda expression body does not access variable in the closing scope. So we will get into much details of this when we cover our example spot. So the next one is the parameters. Now this is the optional parameter list also known as the lambda declarator you can admit the parameter list if you want a function that takes zero arguments. Then we have the return types declaration as you can see on your screen now this is basically the return type most of the time the compilers can deduce the return type of the lambda expression when you have zero or one return statement. However if it makes it easier to understand the code you can specify the return type now there are some differences among compilers regarding the automatic detection of return types when you have more than one return type statement because the standard does not guarantee the automatic detection of return types. Now notice that the specification of the return types is basically based on the optional return value syntax that is introduced with C++11 which puts the return value after the function. And now to talk about the last thing that is lambda statements that is basically the body of the lambda function the statements within the lambda body can access the captured to variables and the parameters that are passed into that lambda function. So let's move on to the examples path now. So let's move on to our compiler for that. And we will start on with a very simple example in which we will make everything equal to let's say none because we are going to have no capture clause we are going to pass in no arguments that return type is going to be white and in the lambda statement part we are going to be printing a simple statement that it's going to be a C out statement. So we already have this texture in the main function what we are going to do is that we are going to write in auto lambda. Since this is a lambda function and first we will define these brackets that are for the capture clause and these are going to be empty which means that this function basically wants in no capture clause. Then we are going to define empty brackets which means that it is also going to have no arguments and then we are going to specify the body as you can see that I have skipped the return type declaration and now I have skipped that when I skip that the compiler will deduce that the return type is basically white if you I want to have some return type I would have specified it here but in this case the return type is going to be void and the compiler is going to deduce it by himself that the return type is white since I have written nothing over here. So in here we are going to have a simple C out statement which is going to say let's say it's going to say I am a lambda function. And finally we have to put a colon in here and now what we are going to do is that we are going to call the function as lambda and then if we just run this code you can see the output right here on your screen that say I am a lambda function. So this function has been called using the name with which it has been actually initialized. So this is the way you have to call in lambda functions and lambda functions is going to be called in automatically. Now as previously explained some components of the lambda definitions are optional so if you write in three lines these are going to be completely equivalent. So let me just write in those three lines. So first we have let's say this very same line. So we are going to just copy this from here. Paste it right here to just show you as you can see that the first one in which we have no capture clause no arguments no return type and we have done this body that have a simple see out statement. Now if you just write in here and just paste it very same thing and right here in these parenthesis if you write in white which means that it includes the parent parenthesis for the parameter list with the white keyword now this means that it is going to return in and we are going to if you write in white over here this means that it is going to receive in no arguments and this statement above and this statement below have the very same meaning you can write it in both ways whatever you like. Now the third one is that you can also specify the type as I told you that if you don't write anything over here this would the compiler is going to assume that the return type is going to be white but if you want to write in something here for your satisfaction then you can write in white like this and arrow and then this white statement added is going to have the very same output. So let me just show you how all this stuff is going to work this is basically the first way this is the second way and if I just remove it from here copy this from from here and then paste it right here and write in white over here and these are the three basically ways and these three lines show basically the very same examples of the definition of a lambda expression. So let me just use them right above here. So I will just remove it. You now know the three ways so we can as I told you use white over here. So if I just run it you're going to see that it's going to print out the very same output. And if we talk about the third way we have to put in the return type that is going to be white and now if you just run this code you are going to yes you're going to witness the very same output that says I am a lambda function. So these are the three ways in which you can initialize this very same function that is going to print out the very same output white here means that there are no arguments which this function is going to receive and this white means that this function is going to return nothing. So now let's move on to an example in which we are going to receive in some arguments. So for example we are going to receive in two arguments. Let's say the first one is an integer value x and then we have an integer value y. And let's just remove it for now. All right now in this function what we are going to do is that we are going to let's say just print out the sum of those two numbers sum of numbers is and in here what we are going to do is that we are going to write in x plus y simple enough. All right now the place from where we are calling this function we have to actually pass in some arguments to this function now. So for example the arguments are three and four. So now if you just run this function you are going to see right in that it says sum of numbers is seven. So this is how you can actually pass in arguments to a function now for example you want to call this function again with let's say some other arguments like say let's say this time we want to pass in five and six to this function. So if you now run this code you can see that it says first sum of numbers is seven that is for the first two inputs and then it says the sum of numbers is 11 that is for the second set of inputs. And to now discuss on with the final case that is when this receives in some arguments and then it also has to return some value. So in that case what we are going to do is that we are going to specify the return type as well. So for example what this function is going to do is that it's going to let's say return an integer value then in that case what we are going to write in after this is we are going to write in this arrow and then we are going to write in it which means that the return type now is going to be an integer value and what is going to return is let's just cut this out and we are going to write in return the sum of those two numbers we are going to write in return x plus y. So we'll just remove this second statement from here and we will operate it for these two values. So it printed out nothing because we haven't store it in some variable we have to store it first we have to write in a equals to lambda then we have to see out the sum of two numbers is and then we are going to write in a that is the value that is stored. So now we are going to run it and you can see right in that says the sum of two numbers is 7. So this is how basically you can just add a return type as well in this very same function. So this is how lambda functions can be used in your C++ programming this was the syntax and the use as well. In the future tutorials you are also going to have some more tutorial on lambda expressions and you will then come to know about certain building function in lambda expressions for example you are going to learn about for each method and many others as well. So for now let's move on to the conclusion part. So we have basically provided some very simple examples that allowed us to focus on the new syntax that was introduced by C++ 11 lambda expressions. You can apply all the things learned in these examples in a more complex scenario such as when you call an STL method or you work on the libraries that require functions that can be replaced with lambda as happens with threading building blocks. So I suspect you will find that once when you start using C++ 11 lambda's so when you start on using C++ 11 lambda's there is no going back. So that's it. I guess with this tutorial and in the next tutorial we will cover more features that were added in C++ 11. So thank you so much guys for watching and I'll see you guys in the next tutorial. Hey guys, what's up? This is Omar Khan and I welcome you to another tutorial on this section in which we are discussing the new features that were added in C++ 11. In this tutorial we are going to be discussing about uniform initializations. Now uniform initializations is a feature in C++ 11 that allows the usage of a consistent syntax to initialize variables and objects ranging from primitive type to aggregates. In other words, it introduces brace initialization that uses braces to enclose initializer values. Now the syntax is shown right here on your screens. You can see first you have to specify the type then you have to specify the variable name and then you have to specify the arguments. Now there are some of the different ways of initializing different types in uniform initializations. Let me just show you how this is done. So we'll move on to our compiler and we don't want to output anything. What I need to do is I need to only show it to you that how we are going to do it. Now the first one is the uninitialized built-in type that is a simple integer like this. This is basically the uninitialized built-in data type. Now the second one is the initialized built-in type that is basically something that has a value as well. For example, if you just make it equal to int i equal to 10 that it is no more an uninitialized. It is an initialized built-in type. Then in the initialized built-in type, we have one more type that is for example, if you write in something like int k and we specify some value right in here, let's say it v2. So this is also an initialized built-in type. Then we have the aggregate initialization in which we have something like int a and specify the size right in here and then make it equal to some set of elements. Let's say this. So this is basically aggregate initialization. Then we have the default constructors and parameterized constructors to talk about the default constructors. It looks something like for example, if we have the constructor a and then this is going to be v1 is going to be the object for this. So this is basically the default constructor to talk about the parameterized constructors. What we are going to do is that we are also going to pass in, let's say some arguments. Let's say one is going to be passed in to the function. So then we have the parameterized constructor with a single argument. You can, for example, if you have a single argument, which in this case is it is also a single argument, you can pass it in one more way. You can just write in the name of the object and you can make it equal to one. So this one is going to be passed in to the parameterized constructor as well. And then finally we have the copy constructors in which what we are going to do is that we are going to copy from one object to another object. Now this very same thing is initialized using brace initialization. Then this very same initialization which we have done here can be rewritten in a different way. Now, for example, the first one was the uninitialized type that looks something like this. Now, if this is initialized using the brace initialization, then it would look something like this. And for the second one that is the initialized building type, this thing right here can be written in the very same way. This is written right here. For example, if it i equal to 10, then for brace initialization, this can be done it like this. So the next one is the aggregate initialization, which will look the very same way when you are dealing with the brace initialization. Similarly, if you talk about the constructor and the structure, then it is going to look a bit different. For example, the default constructor is going to look something like, for example, this is going to be class a for example, then x one is the object. Then for brace initialization, you have to add these brackets for the default constructor. For the parameterized constructor, it is going to look the very same way and for the copy constructor that is right here in brace initialization, this thing right over here that is actually the copy constructor. It is going to look something like a and you have to write in we one. Then the object to which it is going to be copied is going to be written right in the brackets. So this is how this can be done using brace initializations. So now if you move ahead, the next thing is the application of uniform initializations. Now there are four applications of uniform initialization. The first one is the initialization of dynamically allocated arrays. The second one is the initialization of an array data member of a class. The third one is the initialization of an array data member of a class and the fourth one is the implicitly initialize function parameter. So let's start on with the first one that is the initialization of dynamically allocated arrays. So let's just see an example of how it will be done. So we will just move on here. We will remove this stuff from here. And now what we are going to do is that we are going to write a simple C plus program that is going to demonstrate the initialization of dynamic array in C++ using uniform initialization. So this library as you know from the start that this is going to be included right in here. So the next thing we are going to do is that we are going to call this main function. And what are we going to do in this main function is that first we are going to declare a dynamic array, then we are going to print the contents of that array and the dynamic array which we are going to declare is going to be initialized using braces. So for example, it is an integer array, which means that it store integer elements. So it is going to be an integer pointer since it is going to point towards the element basically and it is going to be created using new int, which means an array class is going to be called in. Five are going to be the number of elements in that array and let's say the elements are one, two, three, four and five. Now, if you want to print the contents of that array, what we are going to do is that we are going to use the for loop int i equal to zero since we are going to start on from the very first element, then it is going to iterate until i less than five and then finally i plus plus. So in this loop, what we are going to do is that we are going to write in C out and we are going to write in five plus i. So for the first time, it is going to print out the first element, then it is going to keep our trading until the last element. So let's just run this code and equal to sign over here and here is the output that says one, two, three, four, five. That is the output of this program that has printed out the elements of the dynamically allocated array that was initialized using the brace initialization. So this was a very simple example of the first case that is the initialization of dynamically allocated arrays. So the second one is the initialization of an array data member of a class. So that's also just got an example for how this is going to work. So I'll just remove this and we are going to write in a C plus plus program to initialize an array data member of a class with uniform initialization. So in this case, we are going to create a class right after this. And in this class, what we are going to do is that we are going to create an array of let's say the size of the array is four. And after this, we are going to initialize an array using uniform initialization and that array is going to be public in this case. So what we are going to do in here is that we are going to create a and then we are going to receive the elements in this constructor function that are and x and y and z and let's say next element is in W. So right in here, what we are going to do is that we are going to insert these elements in the array. So these are actually the elements of that are going to be received in this constructor function. And now what we are going to do is that we are going to actually simply insert these elements into the array. So since this is a single line, let's just do it like this. And then you're going to write in the name of the array and then you are going to write in x, y, z and w and finally these brackets and these are basically the brackets of this constructor function. So now after this, what we are going to do is that we are going to create a function that is the print function. And this print function, what we are going to do is that we are going to simply print out the elements of this array. So we are going to use a for loop for this and we are going to write in for int i equal to zero. i is less than four i plus plus. And in this follow up, what we are going to do is that we are going to simply see out the array elements as we did in the previous case. So it is going to be array plus one, not plus one, it is going to be I. And finally, this, and now right down here in the main function, what we are going to do is that we are going to create new object. And the number to initialize the array with will be passed into as arguments to the constructor. So we are going to write in a a we are then going to pass the elements, let's say the element are 123 and four, then using this object we have created, we are going to call in the print function. And finally return zero. Now one more thing we need to do in here is that you have also Yes, we already have this. So let's just run this code. So you can see that it printed out the elements of the array. So this was how you can basically initialize an array data member of a class and print the elements of the array. Now, the third case is the implicit initialization objects that is to return. So let's also see an example of how this is done. So we'll just remove this stuff from here. We will remove this stuff from here as well. And we are also going to create a class in this case. And in this class, what we are going to do is that we are going to create in two elements, that is int x and int y. And we are going to basically implicitly initialize two objects, and we are going to return these values, whatever will be these values. And these values will basically what is going to be passed in when the object is implicitly created. So we are going to create the constructor function that is going to be public. And in this, what we are going to do is that we are going to receive in two values, let's say int a and int b. And what we are going to do with these value is that we are going to write in a, not a, we are going to write in x a and a comma, then we are going to write in y b. And then finally, this is the body of the constructor function. So basically, this is called the implicit initialization of an object to return some values. So this is what is going to return the values for us. Basically, this int x and this int y is going to store these values and then these values are going to be returned. Now how these are going to be returned for that, we have to create a print function that is going to print out the elements. And in this print function, what we are going to do is that we are going to see out the value of a, and then we are going to see out the value of b. Now what we are going to do is that we are going to actually return these values. Now how these values are going to be returned, this print function is also going to be public in this case. Now, right after this, what we are going to do is that we are going to create an overloaded constructor. And the compiler is going to automatically deduce that the constructor of the class a needs to be called and the function parameter of the function are basically going to be passed here. So how this is going to be done, we are going to write in the name of the class, then you have to write in anything like f. And then you have to write in the values that are int a and int b. They are going to be x and y in this case, and x and y here as well. Because these are actually the values that are now stored in as public right above here. Since these values are only visible into a and this int b are only visible to this constructor function since these are the arguments passed into this. So we are going to use this x and y in which the values are actually passed in. Now in this function, what we are going to do is that we are going to write in return a not a x and y. Now, the compiler is automatically going to deduce that the constructor of class a needs to be called. And the function parameter of this f right here are needed to be passed here. Now, if you talk about the main function, right in here, what we are going to do is that we are going to first create an object. And we are going to write in F, then we are going to pass in some values, let's say one and two. And then using this object, you are going to call in the print function and finally return zero. Yes, one mistake we did here is that we have to make this function out of this class because if and yes, one thing we have to do in here is that we have to declare this stuff out of this class because if you don't do so, this statement that is a xf one two is going to generate error. Now why it is going to basically generate error is because this thing is outside the scope of this call, for example, by just press control Z. And this statement is right in here and you run this code. You're going to see an error generated that says F was not declared in the scope. But if you just remove this and paste it right in here, this statement over here is going to excesses. Now, how is the compiler going to know that this constructor is going to be called as I told you earlier that the compiler is going to automatically deduce that the constructor of class a needs to be called and the function parameter of F are needed to be passed in here. So these values are going to be then returned here. And what this extra print is going to do is that it's going to call in this function. And it is going to print in basically this error here is going to tell it that it is the part of the class a. So it is going to receive the values of this x and y. And these are going to be returned from here and printed using this statement. So if you now just run this code, it is not going to generate any error, I guess. And yes, it didn't. And it has also printed out the values for us. So this was the third case that was if implicitly initialize the object to return values. Now the final and the fourth case is implicitly initialize the function parameter. So let's see an example of this as well. So we will remove this stuff from here. And we will also remove this stuff from here. Now what we are going to do is that we are going to create a C plus plus program to demonstrate how to initialize a function parameter using uniform initialization. So the same we are going to have a class a and then we are going to have two variables, let's say int a and int b. And then in the public constructor, what we are going to do is that we are also going to receive in two values, int x and it wide b. And with these values, what we are going to do is that we are going to actually store them and where we are going to store them in these variables. So we are going to write in a x and a y. And then this is the body of the constructor function. And now right in here, what we are going to do is that we are going to create print function as we did in the previous example. And we are going to simply see out a, see out b. Now you don't need to get confused that in the previous example, I have written x and y here and now I'm writing a and b here. That's because I have actually initialized a and b in here. In the previous case, I have initialized x and y here and int a and in b in here. But now I've just reversed it. So that was not on purpose. That was just declared. So we have to use an a and b in here and a and b right here as well. And this needs to be white print. Now what we have to do is that the very same way we have to create. Now in the previous case, as you know that we have actually used the constructor. Now what we are going to do is that we are going to now create a function actually. And we are going to first write in the name of the function. And then we are going to write in this x that is the object. And in this function, what we are going to do is that we are going to call in the print function. And in here in the main function, what we are going to do is that we are going to call the function and initialize its argument using the brace initialization. So we are going to write in F. And then right in here, we are going to use the brace initialization and we are going to pass in the value. Let's say the value are one and two. And we are going to write in return zero. So if you just run this code, it is going to solve our case number four. Right, it says expected unqualified ID and then it says multiple initializations given for this a. So yes, this needs to be removed from here and this has to be by. So now let's just run it again. And right here, it has generated the output we required that are the elements that is one and two. So it has the very same logic that the compiler is automatically going to deduce that the function of class a needs to be called in the function parameter of void function that was declared outside that class are going to be passed into this print function that is going to print out the values for us. So first, the values are going to be received in this. These are going to be copied in the global variables right here that are initialized. And then these are going to be printed using this function. So that's it with case number four. So I guess that's clear. So that's it with this tutorial as well. So this is how basically uniform initialization is used in C++ 11. So I will see you guys in the next tutorial where we will cover more on the features added in C++ 11. Thank you so much for watching. And I will see you guys in the next tutorial. Hey guys, what's up? This is Sumer Khan and I welcome you to another tutorial on the section in which we are discussing about the new features that were added in C++ 11. So in this tutorial, we are going to be learning about the deleted and defaulted functions. So let's start on with the default. Now explicitly defaulted function declaration is a new form of function declaration that is introduced into the C++ 11 standard. You can append the equal to default that is a built-in word. This specifies to the end of a function declaration to declare that function as an explicitly defaulted function. Now the compiler is going to generate the default implementation for explicitly defaulted functions, which are more efficient than manually programmed function implementations. Now a function that is explicitly defaulted must be a special member function and has no default arguments. Explicitly defaulted function can save your effort of defining those functions manually. So if you have a class that is defined with any constructor, the compiler will not generate a default constructor. Now this is useful in many cases but it is sometimes waxing. For example, if I just show you an example and I move on to my compiler and I have for example a class A and in this class A I have a public constructor that looks something like A and that also receive an arguments let's say A and this is the body. So in the main function if I just write in A, A then the compiler will complain that we have no default constructor. For example, if I just run this code you can see that it is generating an error that says no matching function for call A to A. It says the candidates are A into A. Candidates expects one argument zero provided and many other type of errors. Now these errors are basically generated because the compiler did not make the one for us because we already have had one that we defined. Now we can force our compiler to make the one for us by using the default specifier. For example, if we have this very constructor right in here and let's say we define one more constructor that receives in no argument and we define it as default. So now if we do the very same stuff that is AA and we run this code you can see that it ran perfectly because the compiler did not complaint about this anymore because when this was called in it excess this that was the default constructor. So you can basically declare both inline and out of line explicitly defaulted functions. You can declare a function as an explicitly defaulted function only if the function is a special member function and has no default arguments. The explicitly defaulted function declaration enable more opportunities in optimization because the compiler might treat explicitly defaulted function as trivial. So this is how default works in C++11. Now there was one more feature that was added. We are also going to discuss that that was the deleted. Now the C++11 standard basically introduced deleted function declaration as a new form of function declaration. Now to declare a deleted function you can append the equal to delete as in the previous case you have to append equal to delete sorry the equal to default specifier so in this case you have to append the equal to delete specifier to the end of a function declaration. The compiler prohibits the usage of a deleted function. For example you can declare the implicitly defined copy constructor and copy assignment operator of class any class let's say class A as deleted functions to prevent object copy of that class. So for example we have a class that is going to have a constructor that is going to take an integer. So it is going to be a class A and it is going to have a public constructor int A and we don't have this stuff right in here. Then if we just move on to the main function then we are going to write in first A A10 which means that we have actually called in this constructor that is having some argument. So this statement is going to work perfectly this is going to be a correct statement. Now the second statement is let's say we initialize one more object and pass in let's say a float value to it let's say the value of pi 3.14. So this is also going to be okay because the 3.14 is going to be converted to an integer of 3 and this part 14 that is the decimal part is going to be truncated itself. Now if you write in A equals to B so this is also going to be okay because we have a compiler generated assignment operator however what if that was not we wanted we do not want the constructor allow double type parameter nor the assignment to work. C++11 allow us to disable certain feature by using delete. So what we are going to do is that we are going to actually disable the conversion. So we are going to write in here we are going to have the very same constructor then what we are going to do is that we are going to create A that is going to have double and we are going to write in delete. Now what does this mean this means that the conversion has now been disabled and we are going to write in A it is going to equal to and this is basically that the assignment operator has been now disabled. Now if we write the code that is the very same here in the main function a a e a a then this is going to be completely fine but now if you write in A B that is 3.14 this is going to generate an error because conversion from double to integer has been disabled. Write in here as you can see that we have disabled the conversion to double using this constructor and using this delete specifier and secondly we also have this line that is equal to B that is the assignment operator line so this has also been disabled right here so this line is also going to generate an error. So basically the purpose of the delete specifier is to actually disable certain features in C++ which you want to disable for example in the previous case when you passed in this 3.14 to this very same constructor that is expecting an integer value so what it's going to do with that double value that it's going to convert that double value into an integer value by truncating the decimal part for example you don't want any decimal value to be passed into this constructor function so what you are going to do is because this is the default behavior of C++ compiler to actually convert this so what you want in your code was that for example you don't want any conversion from double to integer you only want this function this constructor to receive an integer value so what you are going to do is that you are going to use the delete specifier and you are going to disable certain feature and in this case we have disabled two features first we have actually stopped the conversion and secondly we have disabled the assignment operator so these two lines are going to generate an error message for us and I guess this has to be a build-in world that is operator over here that is going to actually stop the assignment operator this has to be a build-in work so if to write in the complete operator as you can see that it also has been bolded by the compiler itself so now these two lines you are going to see that they are going to generate an error so you can see that it says line number 19 that is the use of deleted function a to double is not allowed secondly in line number 20 as you can see right in here use of defaulted function a and operate which means that the assignment operator has also been disabled so in this way we could achieve what we intended so once you have used a deleted keyword with a function then the compiler will prohibit the usage of a deleted function for example you can declare the implicitly defined copy constructor and copy assignment operator of class a as deleted functions to prevent copy object of that class for example you can declare the implicitly defined copy constructor and copy assignment operator of class a as deleted functions to prevent the object copy of that class so let me give you one more example of what i'm talking so we will have this very same class in which we have a public constructor and this public constructor is going to be empty it's going to be something like this and then we will actually disable the copy constructor and we will disable the copy assignment operator now you know that copy assignment operator is deleted in this way that it was an operator equal to constant a and and then we are going to delete this now to disable the copy constructor what you are going to write in you are going to write in a very same way this one is written right in here and then you are going to write in it is going to equal to delete so simply the name of the class the constant and then a address so this is going to be deleted which means that this assignment for the class the address pointing that address is going to be deleted so if we have in the main function we will just remove this stuff from here and for example we have the object one that is a1 and then if we use the copy constructor for example if i just write in a a2 that is an object 2 and we may i make it equal to a1 so this is going to generate error because the copy constructor has been disabled already so if i just run this code you're going to see that it is going to generate error that says use of deleted function which means that a function that was deleted has been used which is not allowed and it was deleted right up here so the second thing was the copy assignment operator and it is going to be the very same as it was in the previous case for example we have an object 3 and i just write in a3 equal to a1 so it is also going to generate error as the previous one had generated an error so i will just comment it out so that you can see this error so you can see right here that it says use of deleted function and it is the very same so in this example although only one copy constructor and one copy assignment operator are declared as deleted function explicitly the compiler can detect the declaration of the user defined copy and copy assignment operator so the compiler will no longer explicitly define any other copy constructor or copy assignment operator that have different parameters so in this case the copy and assignment operations between the class objects are totally prohibited so this is how delete function actually delete specifier actually work you can disable the features you want to disable so this is it with this tutorial you now know the two keywords that were introduced into c++11 the default and the deleted specifier so that's it with this tutorial thank you so much guys for watching and i'll see you guys in the next tutorial hey guys what's up this is Umar Khan and i welcome you to enter the tutorial on this section in which we are discussing the new features that were added in c++11 so in this tutorial we are going to be basically discussing about null pointer so c++11 basically introduced a new keyword null ptr as a null pointer constant the null pointer constant can be distinguished from integer zero for overloaded functions the constants of zero and null are treated as of the integer type for overloaded functions whereas null pointer can be implicitly converted to only the pointer type pointer to pointer member type and boolean type so before c++ if you talk initializing null pointers with zero or null makes it impossible to distinguish between a null pointer and integer zero for overloaded function for example if you see the following two functions as mentioned on the slides you can see that the first one is receiving an integer value and then the second one is receiving a pointer actually so when you call the overloaded function with this statement that is the funk and then you pass in null to it so can you guess which function is going to be called now you might be thinking that this second function over here that is white funk character steric s this should be called because the actual parameter null looks like a pointer however surprisingly the call funk null resolve to funk int the top one here this call is going to call this now why is this going to call the above function because null is a macro and equals to the integer zero which is of the integral type instead of the pointer type now to solve such problems of null pointer constant c++11 introduced a new keyword that was null ptr the null ptr constant can be distinguished from integer zero for overloaded function for example if you see the very same example right on your screen and call the previous overloaded function with this statement now that is the funk null ptr then can you guess what function is going to be called yes now you are correct because this very same function is going to be called now a null pointer constant with the null pointer value has some characteristics the first characteristics it has that it can be converted to any pointer or pointer to member type secondly it cannot be implicitly converted to any other type except for the boolean type third it cannot be used in an arithmetic expression fourth it can be compared with the integer zero and fifth it can be used in relational expressions to compare with pointers or data of the standard null ptr type now it should be noted that in c++11 it is still acceptable to assign the value zero or null to a pointer now what are basically the difference between null and null ptr so basically null is a manifest constant as defined by c that is actually an integer that can be assigned to a pointer because of an implicit conversion whereas if you talk about null ptr it is a keyword that is representing a value of self defined type that can be converted into a pointer but not into integers so as you can see right on your screen you can see some example the first one is int i equal to null then you can see the very same i equal to null ptr and then you can see a pointer that equal to null and then you can see a pointer p that equal to null ptr now can you guess which statement is actually correct and which statement is wrong now the first statement over here is completely correct because you can initialize an integer to null but if you talk about the second one it is going to generate an error because it is not an integer convertible value if you talk about the third one it is completely okay because integer is converted into a pointer whereas if you talk about the fourth one it is also going to be perfectly all right and why it is going to be perfectly all right because of the very same reason we discussed in the previous slide so that is important to solve an ambiguity that can arise in generic programming now suppose you have again two overloaded functions as you can see on your screen the first one is void func and is receiving and is expecting to actually receive an integer value and the second one is void func that is expecting to receive a pointer value so now if you make the very same call as you did in the previous case you call in func null then you are actually calling two things first you are calling the variant being null and integer but func null pointer that is right in here it will call the second variant being null pointer not an integer now to avoid the risk to call one function instead of another always use a zero if you want an integer and null pointer if you want a pointer so i guess that's clear so this was basically the purpose of null ptr to conclude my statements null ptr was only added to remove the ambiguity about zero and now since those two were treated as the very same by the compiler so to remove that confusion c plus plus 11 basically introduced this keyword that was the null ptr so i guess that's clear so that's it with this tutorial as well thank you so much guys for watching and i'll see you guys in the next tutorial hey guys what's up this is umar han and i welcome you to another tutorial on this section in which we are discussing the new features that were added in c plus plus 11 so in this tutorial we are going to be discussing about the feature that is a telegating constructors that were added in c plus plus 11 before c plus plus 11 common initialization in multiple constructor of the same class could not be concentrated in one placed in a robust maintainable manner so partially elevated as problem in the existing c plus plus program you could use the assignment instead of initialization or add a common initialization function now with the delegating constructor feature you can concentrate common initialization and post initializations in one constructor named as target constructor now delegating constructor can call the target constructor to do the initialization a delegating constructor can also be used as the target constructor of one or more delegating constructor so you can use this feature to make program more readable and maintainable now delegating constructors and target constructors present the same interface as other constructors target constructors do not need special handling to become the target of a delegating constructor they are selected by the overload resolution or template argument detection now after the target constructor completes its execution the delegating constructor gets its control back a delegating constructor can be a target constructor of another delegating constructor thus forming a delegating chain the first constructor invoked in the construction of an object is called the principal constructor a constructor cannot delegate to itself directly or indirectly the compiler can detect this violation if the constructor invoked in a recursive chain of delegation are all defined in one translation unit now you can use the delegating constructors feature interacting with other existing techniques that includes first when several constructors have the same name name and overload resolution can then determine which constructor is the target constructor secondly when using delegating constructor in a template class the deduction of template parameter works normally now if you talk about c++ three there are often cases where it would be more useful for one constructor to call another constructor in the same class unfortunately this is disallowed by c++03 commonly this end up resulting in either duplicate code or use of an initializer non constructor function to keep the common code accessible to both constructors that need it now how does it actually look like with c++03 and how it was then corrected by c++11 i will give you an example of that and then you will be much more clear of what i'm talking so here we are so in here for example we have a class a and in this class a what we are going to have is that we are going to have a public constructor and this is our constructor body so for example if we have one more constructor here that receives some value a and for example we have to write some code in here that is named as code one and then in here we have to write in some code two but we also want to use code a so what we are going to do is that we are going to write in code one write in here again so as you can see right in here that the code one is defined twice and as i talked about that use of initializer a non constructor function when you have to write in the common code or you have to write in the initializer a non constructor function to keep the common code accessible to both constructor so in that case this very same code is going to look something like we are going to have this very same a function and in here we are going to have i and i t that is the initializer for let's say let's call it as x and then right in here in the second function we are going to have this very same initializer that is i and i t x and as you can see right in here that the code to write in is here the code to write in this is right in here and now for example we have a white i and i t x right in here and in here for example we have to write in code number one so while using the i and i t method it is considered a better practice than duplicating code now it has a couple of downsides as well first it's not quite as readable as it adds a new function and several new function calls second because i and i t x is not a constructor it can be called during the normal program flow where member variables may already be set and dynamically allocated memory may already be allocated this means that i and i t x needs to be additionally complex in order to handle both the new initialization and reinitializes cases properly now c plus plus 11 actually solves these problems and it adds the ability to chain constructor together that is also called as delegating constructor for which i've been talking at the very start now how this is going to actually help you that we are going to have this very same thing in which we are going to have a class a then we are going to have a constructor and in here for example we have to write in code number one and then we have the second constructor that has some argument then what we are going to do is that for example in here we want code number one and code number two as well so now what delegating constructor is going to help us that we don't have to write in this code now how this constructor that is receiving an argument is going to get this code is by the property of c plus plus 11 to actually chain the constructor now how this constructor is going to be chained to this constructor is a very easy task you all may have to add this constructor after this so this constructor that is receiving no argument is going to actually be chained to this constructor that is receiving an argument and code number one and is automatically going to be accessed by this constructor so as you can see that it is much cleaner so one thing to note you should always use the initialization list syntax when delegating constructor as compilers that do not support delegating constructor will generally flag this as a compiler error so if you try to call one constructor from the body of another constructor the compiler will not complain and your program may also not behave as expected so this is how basically constructors are chained and your code looks much cleaner much easier the duplication of code is also removed as you can see that this code one and code two is used by this as a whole and this constructor only can use code number one so i guess that's it with this tutorial thank you so much guys for watching and i'll see you guys in the next tutorial hey guys what's up this is Umar Khan and i welcome you to another tutorial on this section in which we are discussing the new features that were added in C++11 in this tutorial we are going to be discussing about the r-value references but before discussing r-value references you need to know about what is passed by value so when a function gets its parameter as by value it does copy the compiler knows how to copy it if it's a user defined type we may need to provide the copy constructor and probably the assignment operator as well to be able to do a deep copy however copying process is expensive actually there are a bunch of copying going on when we use the stl containers when an object tossed in by value since it's a temporary object we are really wasting our precious resources including the cpu as well as the memory and so on so we need to find a way to avoid such an unnecessary copy now the question arises why our values were introduced so the primary purpose of introducing an r-value is to actually implement move semantics so what is move semantics so before moving ahead you need to know about this term in c++3 there was a costly and unnecessary deep copies that can happen implicitly when objects are passed by values we can avoid the performance hit due to the deep copy by using an r-value references now we have a way to determine if a reference variable refers to a temporary object or to a permanent object so how it can be used the main usage of r-value reference is to create a move constructor and a move assignment operator if you talk about the move constructor it acts like a copy constructor it takes an instance of an object as its argument and it creates a new instance from the original object however the move constructor can avoid memory reallocation because we know it has been provided a temporary object so rather than copy of the fields of the object we will move them in other words the r-value references and move semantics allow us to avoid unnecessary copies when working with temporary objects we do not want to move the temporary which will go away so the resources needed for the temporary objects can be used for other objects as well the r-values are typically temporary and they can be modified if we know that our function parameter is an r-value we can use it as a temporary storage or take its contents without affecting the output of our program this means that we can just move the contents rather than the to copy the contents of an r-value parameter this saves a lot of memory allocation and it provides a lot of scope for optimization for large dynamic structures so now let's move on to r-value references so as i told you that the primary purpose of introducing an r-value is to basically implement move semantics r-value references actually enable us to distinguish between an l-value that is actually the locating value or you may say the locator value from an r-value the c++11 standard introduces r-value references which bind only to r-values they are declared with two amster stands rather than one ampersand so let me just give you some example of how r-values look like and how they can be used in c++11 so this is our compiler and in here if you talk about r-value references it actually looks something like you have to write in the type and then you have to add in two addresses then you have to write in the name of the variable let it be ref and then you can write in a value that is 99 so you have to note here that only an l-value can be assigned to our normal reference so if we for example write in int and ref equal to 99 then this part is going to generate error that is the invalid initialization of a non-constant reference to the type this that is int address from an r-value of type integer so if you run this code you can see that it is going to generate an error that says conflicting declaration previous declaration as int and ref or if you just change its name to something like refe it is again going to generate an error because it says that invalid initialization of a non-constant reference of type this from an r-value of type int as I told you before so if you're dealing with this part so if you just remove this from here and you want to do it using a single operator then what you have to do is that you have to first initialize the value for example I just write in int x equal to 2 and then I'm going to actually use this reference and then I'm going to write in the name of the variable actually I cannot make a direct reference so if I now just run this code it is going to run perfectly so in the previous case you have seen that if I just write in some variable here and directly make a reference to it like this it is going to generate error saying that it is an invalid initialization of a non-constant reference to the type int and from an r-value of type int so this is an example of r-value reference now we have let's say two function one that's taking an l-value reference and the other that is taking an r-value reference so how this can be done let's just remove this stuff from here and write above here let's say we have two functions first one is white f that is going to receive a normal one that as I told you that is going to take an l-value which means that it is going to be something like this then in the body of this what we are going to do is that we are going to see out since this is an l-value so we are going to write an l-value reference and we are going to print out the variable and an n-line space so we are going to now create one more function that is going to have the very same name but it's going to use an r-value reference and with this what we are going to do in this body is that we are going to see out since this is an r-value reference so we are going to write an r-value reference and we are going to print out the value so good enough now in the main function what we are going to do is that we are going to do the calling part so first we need to give this i a value let's say the value of i is 10 so now if i just call this function by passing this then what is going to be called it is going to call the l-value reference but if i just pass in some value right in here then what it's going to do is that it's going to call in this r-value reference and why this is going to actually call this as i told you before when i was doing this is an example that if you write in this and let's say you make it equal to x and you make it point towards something then it is going to work perfectly but if you make something like this it is not going to work perfectly but if you make it like some value here and then you point it towards this x then it's going to work perfectly you have to just change this to some other value so now it's going to work perfectly so it's you can see in this example that if you pass in the value so you know that in case of r-value you cannot directly reference a value so in this case since this is not directly referencing a value in this case since first we have initialized a value and then we are pointing towards the integer in which this value is actually stored in that is the variable i so this is going to call the l value and in this case since we are making a direct reference towards this 99 so what is going to do is it is going to call the second function that says r-value reference yeah we missed this one and right here as you can see that it says l value reference 10 and r-value reference 99 so i guess this is clear so if you talk about move semantics here so if you just scroll down here into the main function and what we are going to do is that we are going to call in the f function but what we are going to now do is that we are going to use the move function and then we are going to write in i which means the value has been now passed now what is going to be called actually this function that is the r-value reference function is going to be called now why it is going to be called because that the move i is calling a function taking an r value this is possible because the move takes an l value and it converts it into an r value so an expression is basically an r value if it results in a temporary object so if you just run this code you are going to see the output that says r value reference 10 so you can see that for the first one the l value reference was done but now when you use the move function and pass in the l value it results in calling the r value reference so as i told you that r value is basically an expression that results in a temporary object for example if i have a function right above here and for example i have a function that's return type is int and let's say the name of the function is a and what we have in this function is a variable let's say x is the variable and it is equal to let's say value 2 and then what i do is that i simply return this x now in the main function if you just remove this stuff from here and what you do is that you see out only this a function whatever is returned by this function since this is a returning function and it is going to return an integer value so if you just run this code right now it's going to run yep as you can see that it has printed that value so basically this function a is an r value because if you note that the value being returned is not a reference to the variable x but it's just a temporary value now in c++ 0x we could use a normal or l value reference to bind temporary object but only if it was constant for example i just moved down here and as i'm talking that we could use a normal or l value reference to bind temporary object but only if it was a constant so i mean by this that whatever this reference is going to be it is going to be a constant value as you can see right here for example we can now call in the function a and it is going to be perfectly all right so i'll just remove it from here paste it right here and if i just run this code it is going to run perfectly so no error generated but now if i do the very same and just remove this this statement from here and do not make it constant and run this code it is going to generate error sayings that it is an invalid initialization of non-constant reference of type integer reference from an r value of type in now in c++ 11 the r value reference let you bind a mutable reference to an r value but not an l value in other words r value references are perfect for detecting whether a value is a temporary object or not for example you just remove this statement from here and then you write in constant and an r value and then you call this very same function a then this is perfectly right as it was in the previous case when you use a single and operator but now in the previous case if you wrote in something like this with a single and operator and call the function a it generated an error but now in case of r value since you are using r value now it is not going to generate any kind of error all right this has to be a different variable name let's make it equal to value and this is going to be now perfectly all right so as you can see that the code ran perfectly no error was generated in here so if you just compare those references so how to compare those references we are going to make into functions for that so the first function is going to be for an l value and a constant value that is going to be receiving a constant value and the second one is going to be for an r value so for example let's say the name of the first function is a and it is receiving a constant l value all right so the next function right here is going to be a void and this is also going to be a void function since it's not going to return anything now what it's going to do is that it's going to simply see out whatever value is received in all right so right down here in the second function let's say the name of the function is b then in this function what we are going to do is that we are going to simply see out the whatever value is received in this function and how this value is going to be received this is going to be an r value receiving so it is going to be written with double and operator and then this value so basically the function a takes a constant l value reference and it will accept any argument whether it be an l value or an r value however the second overloaded b steric take only an r value reference in other words by using the r value references we can use function overloading to determine whether the function parameters are l values or r values by having one overloaded function taking an l value reference and another taking an r value reference in other words c++11 introduces a new non-constant type reference called an r value reference identified by the name of the variable and then a double and operator and yes one thing over here this has to be the very same name as it is for this because we are discussing actually the overloading here because when an l value is going to be passed in this function is going to be called in and when the r value is passed into a function this function is going to be called in so you don't have to change the name of these functions the name of these function is going to be the very same what's going to determine or going to tell the main function which functions to be called is it's going to determine by these arguments and how it is going to determine by these argument because this receive only an l value and this receive only an r value so now basically this refers to temporaries that are permitted to be modified after they are initialized which is the corner stone of move semantics so let me give you an example of this so we have very same stuff over here what we are going to do is let's add some professionalism to this and since this is the left value so we are going to write in this and for this one what we are going to write in we are going to write in simply r value and this so now what we are going to add in this is that we are going to add a function that is going to be of integer type and it is going to be the very same function which was initialized in the previous example that was the a function but since now we have already used a function so we are going to use it as b function and in this what we are going to print out we are going to actually print out we are going to first initialize something and then we are going to return it since it is a function that is going to return an integer value so what we are going to do is that we are going to initialize a temporary value and since as you can see right here that we are actually dealing with a value over here so first what we are going to do is that we are going to create a temporary value and make it equal to any number then let's say and then we are going to simply return that temporary value so now in the main function what we are going to do is that first we are going to initialize a value let's say i is the value and make it equal to 11 then what we are going to do is that we are going to call in the a function bypassing in this i and then we are going to call in the a function but now what we are going to do is that we are actually going to pass in this function that is the function b and this is actually the a function and it is actually going to pass in the value 10 so if you just run this code you are going to see yourself what is going on so as you can see that first it says l value for this one it says the l value 11 which means that it is printed out this because this was passed in to the function that was the l value function so it printed out simply this 11 now when you pass in this function what it actually did is that it went to this function it grabbed its value that was stored in this variable since this function was returning this temp value so it grabbed that value put it in these brackets and now this a function was called in by passing in this value so when this value only this value was passed in what it did that it called the r value function and this stuff over here was printed as you can see right on your screens so i hope it's clear so as you can note here that we took out the constant from the void a function that was the l value function actually so that it can take only the l value now we have two distinct functions that can be overloaded one taking an l value and the other one taking an r value so what it basically gives us a way to write more efficient program with less coding so i hope you have understood all these examples so if i just give you a brief summary for what we have been covering so far so basically r value references are added into c++11 and they are basically the declaration r value references and they are new to c++11 secondly non-constant l value reference binds to an object and thirdly r value reference binds to a temporary object which typically will not be used again so these three points actually summarize all the concepts we have been covering for the last 20 minutes so i guess that's clear to you guys so that's it with this tutorial thank you so much guys for watching and i'll see you guys in the next tutorial hey guys what's up this is Umar Khan now welcome you to another tutorial in which we are discussing actually about new features that were added in c++11 so in this tutorial we are going to be learning about automatic type declaration and the declaration type so basically type inference refers to automatic deduction of the data type of an expression in a programming language now before if you talk before c++11 each data type needs to be explicitly declared at compile time that actually limit the values of an expression at runtime but after the new version of c++ many keywords are included which allows a programmer to leave the type deduction to the compiler itself now with type inference capabilities we can spend less time having to write our things the compiler already knows as all the types are deduced in compiler phase only the time for compilation increases slightly but it does not affect the runtime of the program now before moving on to the automatic type declaration you need to first know the use of auto keyword and the normal declaration type and at the end we are going to see an example in which we are going to see that how these two are implemented together so let's start on with the auto keyword the auto keyword basically specifies that the type of the variable that is being declared will be automatically deducted from its initializer in case of functions if their return type is auto then that will be evaluated by return type expressions at runtime so let me just show you a c++ program to demonstrate the working of auto and the type inference so i will just move on to my compiler right in here and what we are going to do in here that we are going to write in a very simple program in which we will have two auto variables first one is going to be auto x that is going to be equal to let's say one and then we have a second variable let's say auto y that is going to be equal to let's say two now we are also going to have a pointer variable we are going to make it equal to pointer and we are going to make it point towards this very first variable that is right in here x so we are going to write in x over here and what we are going to do is that we are going to see out the type id x dot name that is a built-in function and similarly we are going to do it for the other tree as well so we are going to write in type id and we are going to write in y dot name and similarly for the third variable as well that is pointer basically so we are going to write in type id we are going to write in ptr dot name and find the endel now if we just run this code we are going to add a library for this type id as well because it is going to answer which error and that library is basically the name of the library is x that is a standard c++ header file so it is going to be std c++ dot edge and it's going to have this text as well so i guess it's complete now so now let's just run this code so you can see right in here that first we have i right in here then again we have an i and then finally we have ti as an output so in here we have basically used the type id for getting the type of the variables type id is basically an simple operator which is used where a dynamic type of an object needs to be known type id x dot name that is the first one right in here it is basically going to return the shorthand name of the data type of x for example it returns i for integers d for a doubles pi for the pointer to integer at a cycle but actually name is returned that is mostly compiler dependent so i guess that is clear so let me give you a one more example in which we are going to see the use of auto to avoid long initialization when creating i creators for containers so we are going to remove this stuff from here and again we are going to be needing this library that is bit standard c++ header file and now what you're going to do basically is that we are going to create a set of strings and we are going to create an object let's say a for this now what we need to do is that we need to basically insert data into it so using this a what we are going to do is that we are going to call you insert function and after calling this insert function what you're going to do is that you are going to insert data into it so what is going to be the data we are going to insert multiple data elements into it for example the first one is my name then let's say it has my second name and then let's say it's a tutorials and i guess that's it so call them right here so now what we are going to do is that basically this pointer is it is going to evaluate i trigger two sets of string type automatically so what we are going to do basically is you're going to do the for loop and what we are going to do is that we are going to use the auto keyword which is going to help us to evaluate to i trigger to a set of string that is present right in here if we have inserted the three elements that's umar han and then tutorials and what we are going to do with this is that we are going to create one more element that is b a dot begin which means that it is going to start from here which means that it is going to take in from the very start and what it's going to do is it will iterate till the very end so it is going to be until and unless this b right in here it is not equal to a dot end so what it's going to do is that it's going to keep adding it incrementing this one and then in this for loop what we are going to do is that we are going to simply see out the steric which means the pointer of this object b all right so let's just find the right and return zero and i guess let's just run this code so you can see that it says han then it says umar and then it says tutorials so this is how basically the auto keyword is going to help us when using long initialization and it's going to actually avoid the long initialization when we are creating the iterators for containers so let's move on to our slides and the next thing we are going to see is a normal declaration type so the decl type keyword is used for that purpose it basically inspects the declared type of an entity or the type of an expression the auto lets you declare a variable with particular type whereas this type that is the decl type also known as declaration type it lets you extract the type from the variable so declaration type is basically a sort of an operator that evaluates the type of past expression so let me just explain this and it uses what the help of an example so let me just demonstrate a c++ program to use decl type in your code so what we are going to do is that we are going to first remove this stuff from here we are going to be needing this library that is bits standard c++.h and what we are going to now do is that we are going to first initialize two functions right here at the top and then using decl type what we are going to do is that we are basically going to use those functions and using the type id operator as in the previous tutorial we are going to return the type id dot name of those function variables so first we are going to initialize in two variables first function has a return type of integer and let's say the name of the function is a and talk about the body of this function what it's going to do it is going to return simply a variable let's say two since it is an integer function so let's say the second function is a corrector function and its name is let's say b and since it is a corrector function so it's also going to return a character so we are going to write in let's say it's return g so now in the main function what we are going to do is right here first we are going to create actually the variables for those using the declaration type which we did using the auto keyword in the previous previous part so we are going to write in a and then we are going to let's say name it as x as we did in the previous tutorial and then we are going to do the same for the second one that is the function b and let's name it as y and now what we are going to do is that we are going to see out it in this very same manner the way we did it in the previous tutorial type id x dot name and similarly see out type id y dot name and a space of line so writing this return zero let's just run this code so you can see that it says i and c and it has the very same logic as was for the previous case so let me just give you one more example to demonstrate the use of declaration type and for that we will just remove it and in this example we are going to remain simple and be out of the this stuff of functions so what we are going to do is that we are going to initialize a normal variable x equal to let's say two and now what we are going to do is that we are basically going to use the dc l type for this variable x that has been initialized we are going to write in the name of the variable right in here that is let's say a this time and what we are going to do is that we are going to actually increment the value of x let's say we want to increment it by two so now what we are going to do is that if we now see out the type id of a dot name and write and return zero and run this code then in output you are going to see this i variable so this is basically the reference towards the pointer that is basically printed out by this type id variable and i've already explained what this type id does so i guess that's clear about declaration type as well we've already covered an example so now let's move on to automatic type declaration that is basically let you can call it actually a combination of auto and the ecl type so to discuss the relationship between auto and declaration type auto and declaration type basically serve different purposes so they don't map one to one auto is a keyword in c plus plus eleven and later that is used for automatic type deduction the declaration type specifier yields the type of a specified expression unlike auto that deduces types based on values being assigned to the variable dcl type deduces the type from an expression pass to it the value written by declaration type can directly be used to define another variable now auto follows the rule of template parameter deduction while declaration type has rules it should follow defined in the standard for example if you consider the size of operator then similar to that size of operator the operant of the declaration type is unevaluated informally the type returned by the declaration type is reduced using some rules the first one is that if the expression e refers to a variable in local or namespace scope then a static element variable or a function parameter then the result is that variables or parameters declared type secondly if e is a function call or an overloaded operator in vocation the declaration type for that variable e denotes the declared return type of that function otherwise the third rule that is followed is that if e is an l value then the declaration type for e is a template address where template is the type of e if e is an r value the result is the template now these semantics were basically designed to fulfill the needs of generic library writer while at the same time being intuitive for novice programmers because the return type of declaration type always matches the type of the object or function exactly as declared in the source code more formally the rule one applies to unparanthoized id expressions and class members excessive expressions for function calls the deduce type is the return type of the statically chosen function as determined by the rules for overload resolution so now let me give you a very quick example of how auto and declaration type are used together so we will define a c plus plus template function that is going to return the minimum of two numbers the two numbers can b