OK, so now I'm going to try and persuade you that the C++ version is a lot better. Well, to start with C++ directly has a form of call by reference. So it adds to call by value. With a call by reference mechanism. So we don't have to artificially create call by reference. So looking at the C++ version we're going to see a number of interesting things. First off, in our C++ version we're going to use C++ IO. And this IO is going to be type safe and convenient. Type safe. I think you will find it to be intuitive. And convenient, we also have this way of contextualizing where we're using a name space. And we use the name space std because Inside IO stream are things like C out, and they've been defined inside this name space, and that means that their full real name is std. This is called the scope resolution operator, so that's a new thing. It's not in C. It's just a way to get more complicated names and by using name space std I don't have to refer to C. I don't have to give you the full name. It knows that. It should append std and any identifier And search for it, that, if that's available in a declaration, then use that. And now, we have several things going on. We have inline, so our swap is going to be efficient. New feature, informed the, compiler, that we should make this highly efficient. And here is call by reference. So this is to be read as reference to int. Not value of it, reference to it. And same for J. And so when things are past there, they will automatically choose to use the variable locally, without copy. And so the, the, what's passed in is actually, directly manipulable. And whatever happens to its contents, when you return from that function, those changes remain. So you get no call by value overhead, because call by value implies making the local copy, and, so, you sometimes get efficiency by call by reference. That'll be very important later on when we deal with large scale aggregates. And on top of it, we get to modify parameters without having to use dereferencing and addressing operators. So, this looks a lot simpler, this switch, and then these values do indeed get changed. Now, a further interesting thing is, I don't need two names. C++ has overloading. The fact is, I can have more than one swap function in the same context. Now why won't that be ambiguous? This would be the natural question. Earlier languages, like Algol-60 or C, wouldn't allow two functions in the same context to have the same name, it would give you a syntax error or would say that's ambiguous. we have what's called signature matching. So, the compiler provides an automatic, an automatic means of differentiating between the two swaps, and it says, well, if I'm swapping doubles, I'm going to use this. If I were to swap ints, I'd use the other. As long as I can make this distinction, and these things are called signatures, so, overloading involves discriminating by signature, and the signature is the types and number of arguments the function uses. Okay. Let's see how that works. Here's our main. Now, we're in C++. And again, lots of it looks like C, so it's not a huge transition. It's not like you're writing vastly different code from what you wrote as a c programmer. But, we're going to take advantage of what I've told you makes it easier to, to, to use C++ and makes it type-safe. So again, we have our set of variables, our m's and n's for the ints, our x's and y's for the doubles. But here, instead of a printf, I have the C out, and I didn't need to say yeah, I told you before. I didn't need to say standard colon colon scope resolution C out, because the using statement, informed the compiler that it should look for anything with standard in front of it. And now we have what looks like a natural operation. It's sort of why think of the cout as screen, so the cout is secretly the screen and then stuff is going if, we, we can think of this as flowing, stuff is flowing to the screen. And what's flowing? First there is the text inputs. So on the screen, here you're going to see inputs. That would be written out. Now this is normally bit shift, but this operator Is given new definitions again via this mechanism called overloading. And m has the value five, so the next thing that would be printed is five. There's actually a colon here. Then we see a comma, the string ",", and then we have n is 10. And unlike printf, in C++, the IO package in iostream understands the type, and then has default formatting for that type. So it recognizes that this is an int type, and since it's an int type, or an int value, it's going to apply its rules, its formatting rules. So you don't need to give it formatting rules. It just assumes, through its knowledge of typing, which it's keeping, that a certain behavior is expected. Again, that just simplifies your job, and in fact avoids errors. And then the swap function is again what looks like something simpler. You're just passing in the variables m and n. But you're passing them by reference. This was passed by reference. As opposed to passing by value. So, the actual contents will be manipulated and then again you're going to see, later on as your printout here, you will see 10 comma five. Now, how does it know to use swap of double? Well, x and y are doubles. So, it does what's called a signature matching algorithm. [SOUND] Says, I don't use int. I'm going to use the double version, because it's passing me double arguments. So, it has no problem, there's no ambiguity, and that keeps down the name pollution. I don't have to choose to have a whole bunch of different swap names. If swap is strongly related with, doing the same thing but doing it with different arguments, I can keep that name, and it's much more readable code now. It's just simpler to handle. So what we found in C++ is through the miracle of overloading and the signature matching algorithm we've automated the ability of the compiler to select the appropriate function. The two routines to make that, to avoid an ambiguity must have different types or it could have different numbers of arguments. In this case there were different types. So it was able to select properly from the different types. So summarizing, having the same name for conceptually the same activity, in other words using overloading, promotes readability. Readability is among the most important characteristics, a hallmark. It's an absolute hallmark of writing good code. And, if you're going to do pure grading of homework submissions, you should absolutely make readability a the principal guideline in assigning your grade. Overloading based on signature and later the use of generics. So we're going to talk a lot more about generics. And generics are going to be associated with a new idea called a template. It's again an idea in C++ that's very powerful. We'll even make reuse more powerful in the language, and give rise to, a much simpler, both conceptually and in numbers of lines of code, a much simpler code base to do, and, and a more powerful code base. Okay, let's take a little quiz on what we've just talked about. So, standard scope resolution operator, cout, is found in what header file? Inline can be used when declaring what and again a type question, what is the difference between long and long long and int as types? So standard cout is found in iostream along with the overloading of the operator. Semantics for overloading operator midshift. Inline can be used when declaring functions, and it's a speed up. By the way, inline doesn't always get you inlining. It doesn't always get you inlining because you may have a function that's too complicated for the compiler to inline. And the compiler should inform you when that happens. But, you can always ask a function to be inlined. Do you always want a function to be inlined? No, not necessarily. because inlining a function can lead to code bloat. And, it really should be relatively small functions that get inlined because the proportion of overhead from function call to the actual code body of a big function is very, very minimal. Most modern processors have very, very efficient ways to do function call that give you a stack frame and load up the local arguments and do all of that. They've been s-, designed to make function call semantic sufficient. So, you should really stay away from it expect for very, very small functions. And again what's the difference between the types long, long long int? They all allow C++ allows for longer types than at least existed in the standard C language in 1985 though I think many compilers now incorporate this feature. So the idea in C is you have, for example, a short, which might be your shortest integer type. Maybe a short on a standard architecture would let you look at plus or minus 32,000. And then you'd have an int, which would let you look at, a couple of billion. And then next up would be long, and long long, which may or may not be the, the, the critical requirement is that each type be at least each, up the chain. Each longer type be at least as long as the previous types. So, there could be a compiler in which long long and long are essentially the same. That would be legal.