WEBVTT

00:00.690 --> 00:06.350
I introduce function signatures in the first lecture of this section.

00:06.540 --> 00:11.250
And I said the whole thing is the function signatures.

00:11.490 --> 00:14.490
If we have something like Prince

00:18.030 --> 00:27.210
X the whole part of this is called the font function signature.

00:27.630 --> 00:33.860
And one thing we can do with functions is something called overloading.

00:33.900 --> 00:43.500
So if you have this print function it takes in a integer x You could also have another function called

00:43.530 --> 00:44.540
print.

00:44.910 --> 00:55.500
But we can actually change the argument type from Char in this case and we can actually have it also

00:55.500 --> 00:59.090
print a char instead.

00:59.280 --> 01:04.900
It's kind of define this and see what it mean here.

01:05.360 --> 01:15.700
Crunch X in our induce Ouch doing integer

01:20.170 --> 01:33.130
x secreted for an Ruskin to define our other print function that prints the characters.

01:33.900 --> 01:38.200
CEO CH Jean care jare

01:42.260 --> 01:53.220
C endl So notice that the function names are the same but the arguments are different.

01:53.280 --> 01:59.710
So C++ world shoes the proper print function based on the signature.

01:59.950 --> 02:02.240
And that's why signatures are so important.

02:02.280 --> 02:08.240
And specifically it chooses it based on the arguments that it has.

02:08.250 --> 02:11.830
So this is called function overloading.

02:12.090 --> 02:18.540
So we're overloading the print function with more functionality sort.

02:18.940 --> 02:29.890
So if you want to overload a function as a function of the same name the arguments must differ from

02:29.890 --> 02:35.930
each other by the types and or the number of arguments.

02:36.460 --> 02:42.140
Let's actually say print.

02:42.260 --> 02:47.500
It's wondred in print.

02:48.680 --> 02:55.960
The character they say and notice that the compiler doesn't give us any issues.

02:56.820 --> 03:05.940
So if you run this says putting integer one hundred and printing character a so called both of these

03:05.960 --> 03:14.790
functions but our calls Look effectively the same they're the same name but the arguments are different.

03:14.790 --> 03:25.100
OK so the arguments are really what chooses what function gets called so C++ can kind of figure it out

03:25.100 --> 03:25.990
itself.

03:29.090 --> 03:44.710
And we can also have say another print function print each have an X in char see this and that's fine

03:44.710 --> 03:45.230
it

03:51.760 --> 03:56.270
in literally just copy this whole thing again.

04:02.020 --> 04:04.160
So here's Whoa

04:10.370 --> 04:16.410
in we'll call it here print in-seat 200 and B.

04:21.860 --> 04:32.530
And notice that calls are want K says 200 and be called this one.

04:32.610 --> 04:37.770
So the the arguments differ by how many there are.

04:37.830 --> 04:46.680
So it doesnt get confused by this first one because our first one here.

04:46.700 --> 04:59.310
Here it doesnt get confused because this has an integer x and a character C K so function overloading

04:59.310 --> 05:08.040
is really one of those conveniences for when functionality really should be named the same but differ

05:08.040 --> 05:11.680
in the parameters k.

05:11.900 --> 05:19.670
So I tend not to use this all the time but it is quite nice when it's needed.

05:20.240 --> 05:24.890
So in the next lecture we'll be going over default printers.
