WEBVTT

00:00.860 --> 00:08.450
There are situations when you have one or more parameters that have values that are so frequently used

00:08.450 --> 00:14.210
that you want them to be treated as a default value for the parameter.

00:14.210 --> 00:20.600
So while still having the option of allowing the color to provide a different value if necessary.

00:20.600 --> 00:28.520
So to do this, you provide a default value in parameter parameter list of the definition here.

00:28.520 --> 00:31.040
So let's, let's make the void here.

00:31.040 --> 00:36.010
Make a new function named log message here.

00:36.020 --> 00:41.240
First is const string here message.

00:41.840 --> 00:44.420
Of course we have to include the string.

00:45.050 --> 00:45.740
Okay.

00:45.770 --> 00:47.030
Change string to.

00:47.210 --> 00:48.860
Yeah, we have to.

00:50.170 --> 00:51.250
Include.

00:51.520 --> 00:52.360
Include.

00:53.020 --> 00:54.190
String.

00:54.370 --> 00:55.150
Okay.

00:55.510 --> 00:56.650
And.

00:57.680 --> 00:58.780
We have to.

00:58.880 --> 01:01.340
Using namespace STD.

01:03.670 --> 01:05.110
Stayed here.

01:05.350 --> 01:14.680
And then we're going to create another bull here and bull clear screen.

01:15.860 --> 01:18.680
And we're going to equal to false here.

01:18.680 --> 01:26.330
As you can see, this is the first time we use the self initializing parameters in this course here.

01:26.330 --> 01:36.110
So and we're going to add the if the clear screen is true, then clear the clear the screen here, which

01:36.110 --> 01:37.670
we're going to write it here.

01:38.180 --> 01:39.170
Okay.

01:40.160 --> 01:42.050
Void, void.

01:42.050 --> 01:46.130
Clear the screen screen.

01:48.050 --> 01:48.320
Yeah.

01:50.030 --> 01:53.120
And we're going to call the clear the screen.

01:55.690 --> 02:01.580
Where the screen function here is the clear screen returns true.

02:01.600 --> 02:08.830
So in most cases, this function is expected to be used to print a single message, but occasionally

02:08.830 --> 02:12.140
the user may want to have the screen cleared first.

02:12.160 --> 02:17.760
Say for the first message or after a predetermined count of lines.

02:17.770 --> 02:26.260
So to accommodate this use of this function, the clear screen parameter is given the default value

02:26.260 --> 02:27.370
of false here.

02:27.370 --> 02:33.550
But the caller still has the option option of passing a value here.

02:33.550 --> 02:38.530
So now we're going to print the message here.

02:39.460 --> 02:39.920
Okay.

02:39.940 --> 02:45.610
Like this print message here and end the line.

02:45.610 --> 02:55.880
And in the main function, let's call this log message function here and write our message.

02:55.910 --> 02:58.640
First message here.

03:01.500 --> 03:04.290
And then we're going to pass the true here.

03:06.980 --> 03:09.920
And let's create another message here.

03:09.950 --> 03:12.920
This is the second message here.

03:13.220 --> 03:18.910
Without the, uh, without the second parameter bool parameter here.

03:18.920 --> 03:25.610
As you can see, if we made this differently, like if we delete this, as you can see, this message

03:25.610 --> 03:34.670
gives error because the compiler knows if we don't have the second parameter, then the bool clear screen

03:34.670 --> 03:39.260
has to be false and we're going to like abstract virtual.

03:39.260 --> 03:46.120
We're going to have the virtual seven second parameter if we call that like the real world applications

03:46.130 --> 03:46.340
here.

03:46.340 --> 03:46.970
So.

03:48.260 --> 03:52.190
Now here we're going to add another we're going to create a bool here.

03:52.210 --> 03:56.470
So we're going to pass the user's decision.

03:57.400 --> 03:59.200
And here.

04:00.760 --> 04:07.930
We're going to here for, for example, let's, let's make the user decision, uh, true.

04:07.930 --> 04:10.510
And we're going to the log message here.

04:10.540 --> 04:12.940
Log message that third.

04:16.820 --> 04:24.170
Third message here, and we're going to pass the user decision as the variable here.

04:24.560 --> 04:25.190
Let's.

04:25.190 --> 04:25.790
Okay.

04:26.030 --> 04:27.050
So.

04:28.390 --> 04:33.670
Notice that default values occur in the function, not in the function prototype here.

04:33.670 --> 04:42.640
So if the log message function is declared in a header file, the prototype here should be like like

04:42.640 --> 04:49.180
the extern here we're going to add the extern and without these braces here we just have to write the

04:49.180 --> 04:51.190
parameters of our function.

04:51.190 --> 04:57.070
So if we call this function with extern, as you can see here, we're going to get the error here,

04:57.070 --> 04:58.630
but let's delete it.

04:59.760 --> 05:00.080
Oops.

05:00.090 --> 05:01.890
Uh, what's the problem here?

05:02.280 --> 05:03.690
We have the.

05:05.160 --> 05:06.150
Clear the screen.

05:06.150 --> 05:06.300
Yeah.

05:06.300 --> 05:08.610
We have to make it.

05:09.490 --> 05:11.140
Under it here.

05:25.340 --> 05:25.560
Here.

05:25.560 --> 05:26.750
Are we going to comment this up?

05:26.750 --> 05:31.370
Because this is the the program of next lecture.

05:31.370 --> 05:39.410
And as you can see, the compiler showed the tells that we have the problem here and we're going to

05:39.410 --> 05:43.550
firstly undefined reference to clear the screen here.

05:43.550 --> 05:49.850
So now we just we are not we we're not going to using this function for now.

05:51.410 --> 05:52.700
And we're going to delete that.

05:52.700 --> 05:56.270
And as you can see, we show the message on it here.

05:56.270 --> 05:57.320
So.

05:58.390 --> 06:00.130
Let's delete this as well.

06:00.730 --> 06:01.780
Like this here.

06:01.780 --> 06:08.080
And as you can see here, the first message, second message and third message printed here.

06:08.080 --> 06:14.170
And as you can see, the second in the 10th line, we didn't enter the second parameter.

06:14.170 --> 06:20.200
That's why the second, if we don't enter the second parameter, the compiler expects us that the second

06:20.200 --> 06:22.540
parameter is false here.

06:22.540 --> 06:30.100
So if we don't enter the second parameter, the second parameter will be automatically taken as false

06:30.100 --> 06:30.610
here.

06:30.610 --> 06:40.180
So actually you can treat the each parameter with a default value as representing the separate overload

06:40.180 --> 06:41.320
of the function.

06:41.320 --> 06:52.180
So conceptually here the log message function should be treated as two functions as I said earlier.

06:52.180 --> 06:59.810
So if you did, if you define a log message function that has just a const string parameter here, then

06:59.810 --> 07:04.520
the compiler will not know whether to call the function or the version.

07:04.520 --> 07:10.070
The clear the screen is given a default value of false here.
