1 00:00:00,860 --> 00:00:08,450 There are situations when you have one or more parameters that have values that are so frequently used 2 00:00:08,450 --> 00:00:14,210 that you want them to be treated as a default value for the parameter. 3 00:00:14,210 --> 00:00:20,600 So while still having the option of allowing the color to provide a different value if necessary. 4 00:00:20,600 --> 00:00:28,520 So to do this, you provide a default value in parameter parameter list of the definition here. 5 00:00:28,520 --> 00:00:31,040 So let's, let's make the void here. 6 00:00:31,040 --> 00:00:36,010 Make a new function named log message here. 7 00:00:36,020 --> 00:00:41,240 First is const string here message. 8 00:00:41,840 --> 00:00:44,420 Of course we have to include the string. 9 00:00:45,050 --> 00:00:45,740 Okay. 10 00:00:45,770 --> 00:00:47,030 Change string to. 11 00:00:47,210 --> 00:00:48,860 Yeah, we have to. 12 00:00:50,170 --> 00:00:51,250 Include. 13 00:00:51,520 --> 00:00:52,360 Include. 14 00:00:53,020 --> 00:00:54,190 String. 15 00:00:54,370 --> 00:00:55,150 Okay. 16 00:00:55,510 --> 00:00:56,650 And. 17 00:00:57,680 --> 00:00:58,780 We have to. 18 00:00:58,880 --> 00:01:01,340 Using namespace STD. 19 00:01:03,670 --> 00:01:05,110 Stayed here. 20 00:01:05,350 --> 00:01:14,680 And then we're going to create another bull here and bull clear screen. 21 00:01:15,860 --> 00:01:18,680 And we're going to equal to false here. 22 00:01:18,680 --> 00:01:26,330 As you can see, this is the first time we use the self initializing parameters in this course here. 23 00:01:26,330 --> 00: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 24 00:01:36,110 --> 00:01:37,670 we're going to write it here. 25 00:01:38,180 --> 00:01:39,170 Okay. 26 00:01:40,160 --> 00:01:42,050 Void, void. 27 00:01:42,050 --> 00:01:46,130 Clear the screen screen. 28 00:01:48,050 --> 00:01:48,320 Yeah. 29 00:01:50,030 --> 00:01:53,120 And we're going to call the clear the screen. 30 00:01:55,690 --> 00:02:01,580 Where the screen function here is the clear screen returns true. 31 00:02:01,600 --> 00:02:08,830 So in most cases, this function is expected to be used to print a single message, but occasionally 32 00:02:08,830 --> 00:02:12,140 the user may want to have the screen cleared first. 33 00:02:12,160 --> 00:02:17,760 Say for the first message or after a predetermined count of lines. 34 00:02:17,770 --> 00:02:26,260 So to accommodate this use of this function, the clear screen parameter is given the default value 35 00:02:26,260 --> 00:02:27,370 of false here. 36 00:02:27,370 --> 00:02:33,550 But the caller still has the option option of passing a value here. 37 00:02:33,550 --> 00:02:38,530 So now we're going to print the message here. 38 00:02:39,460 --> 00:02:39,920 Okay. 39 00:02:39,940 --> 00:02:45,610 Like this print message here and end the line. 40 00:02:45,610 --> 00:02:55,880 And in the main function, let's call this log message function here and write our message. 41 00:02:55,910 --> 00:02:58,640 First message here. 42 00:03:01,500 --> 00:03:04,290 And then we're going to pass the true here. 43 00:03:06,980 --> 00:03:09,920 And let's create another message here. 44 00:03:09,950 --> 00:03:12,920 This is the second message here. 45 00:03:13,220 --> 00:03:18,910 Without the, uh, without the second parameter bool parameter here. 46 00:03:18,920 --> 00:03:25,610 As you can see, if we made this differently, like if we delete this, as you can see, this message 47 00:03:25,610 --> 00:03:34,670 gives error because the compiler knows if we don't have the second parameter, then the bool clear screen 48 00:03:34,670 --> 00:03:39,260 has to be false and we're going to like abstract virtual. 49 00:03:39,260 --> 00:03:46,120 We're going to have the virtual seven second parameter if we call that like the real world applications 50 00:03:46,130 --> 00:03:46,340 here. 51 00:03:46,340 --> 00:03:46,970 So. 52 00:03:48,260 --> 00:03:52,190 Now here we're going to add another we're going to create a bool here. 53 00:03:52,210 --> 00:03:56,470 So we're going to pass the user's decision. 54 00:03:57,400 --> 00:03:59,200 And here. 55 00:04:00,760 --> 00:04:07,930 We're going to here for, for example, let's, let's make the user decision, uh, true. 56 00:04:07,930 --> 00:04:10,510 And we're going to the log message here. 57 00:04:10,540 --> 00:04:12,940 Log message that third. 58 00:04:16,820 --> 00:04:24,170 Third message here, and we're going to pass the user decision as the variable here. 59 00:04:24,560 --> 00:04:25,190 Let's. 60 00:04:25,190 --> 00:04:25,790 Okay. 61 00:04:26,030 --> 00:04:27,050 So. 62 00:04:28,390 --> 00:04:33,670 Notice that default values occur in the function, not in the function prototype here. 63 00:04:33,670 --> 00:04:42,640 So if the log message function is declared in a header file, the prototype here should be like like 64 00:04:42,640 --> 00:04:49,180 the extern here we're going to add the extern and without these braces here we just have to write the 65 00:04:49,180 --> 00:04:51,190 parameters of our function. 66 00:04:51,190 --> 00:04:57,070 So if we call this function with extern, as you can see here, we're going to get the error here, 67 00:04:57,070 --> 00:04:58,630 but let's delete it. 68 00:04:59,760 --> 00:05:00,080 Oops. 69 00:05:00,090 --> 00:05:01,890 Uh, what's the problem here? 70 00:05:02,280 --> 00:05:03,690 We have the. 71 00:05:05,160 --> 00:05:06,150 Clear the screen. 72 00:05:06,150 --> 00:05:06,300 Yeah. 73 00:05:06,300 --> 00:05:08,610 We have to make it. 74 00:05:09,490 --> 00:05:11,140 Under it here. 75 00:05:25,340 --> 00:05:25,560 Here. 76 00:05:25,560 --> 00:05:26,750 Are we going to comment this up? 77 00:05:26,750 --> 00:05:31,370 Because this is the the program of next lecture. 78 00:05:31,370 --> 00:05:39,410 And as you can see, the compiler showed the tells that we have the problem here and we're going to 79 00:05:39,410 --> 00:05:43,550 firstly undefined reference to clear the screen here. 80 00:05:43,550 --> 00:05:49,850 So now we just we are not we we're not going to using this function for now. 81 00:05:51,410 --> 00:05:52,700 And we're going to delete that. 82 00:05:52,700 --> 00:05:56,270 And as you can see, we show the message on it here. 83 00:05:56,270 --> 00:05:57,320 So. 84 00:05:58,390 --> 00:06:00,130 Let's delete this as well. 85 00:06:00,730 --> 00:06:01,780 Like this here. 86 00:06:01,780 --> 00:06:08,080 And as you can see here, the first message, second message and third message printed here. 87 00:06:08,080 --> 00:06:14,170 And as you can see, the second in the 10th line, we didn't enter the second parameter. 88 00:06:14,170 --> 00:06:20,200 That's why the second, if we don't enter the second parameter, the compiler expects us that the second 89 00:06:20,200 --> 00:06:22,540 parameter is false here. 90 00:06:22,540 --> 00:06:30,100 So if we don't enter the second parameter, the second parameter will be automatically taken as false 91 00:06:30,100 --> 00:06:30,610 here. 92 00:06:30,610 --> 00:06:40,180 So actually you can treat the each parameter with a default value as representing the separate overload 93 00:06:40,180 --> 00:06:41,320 of the function. 94 00:06:41,320 --> 00:06:52,180 So conceptually here the log message function should be treated as two functions as I said earlier. 95 00:06:52,180 --> 00:06:59,810 So if you did, if you define a log message function that has just a const string parameter here, then 96 00:06:59,810 --> 00:07:04,520 the compiler will not know whether to call the function or the version. 97 00:07:04,520 --> 00:07:10,070 The clear the screen is given a default value of false here.