1 00:00:00,900 --> 00:00:08,520 There are situations when you have one or more parameters that have values that are so frequently used 2 00:00:08,520 --> 00:00:14,260 that you want them to be treated as a default value for the parameter. 3 00:00:14,280 --> 00:00:20,690 So while still having the option of allowing the color to provide different value if necessary. 4 00:00:20,700 --> 00:00:28,580 So to do this, you provide a default value in parameter to the parameter list of the definition here. 5 00:00:28,590 --> 00:00:31,080 So let's let's make the void here. 6 00:00:31,140 --> 00:00:36,060 Make the function named log message here. 7 00:00:36,090 --> 00:00:41,280 First is const string here message. 8 00:00:41,880 --> 00:00:47,010 Of course, we have to include the string k change string to. 9 00:00:47,430 --> 00:00:48,900 Yeah, we have to. 10 00:00:50,210 --> 00:00:56,720 Include include string and. 11 00:00:57,720 --> 00:01:01,680 We'd have to losing namespace CB. 12 00:01:03,710 --> 00:01:05,120 Stay here. 13 00:01:05,600 --> 00:01:10,220 And then we're going to create another bowl here. 14 00:01:10,550 --> 00:01:14,690 And we'll clear the screen. 15 00:01:15,960 --> 00:01:18,750 And we're going to equal to false here. 16 00:01:18,750 --> 00:01:26,190 As you can see, this is the first time we use the initial self initializing parameters in this course 17 00:01:26,190 --> 00:01:26,400 year. 18 00:01:26,400 --> 00:01:36,180 So and we're going to add the if the clear screen is true, then clear the clear the screen here, which 19 00:01:36,180 --> 00:01:37,680 we're going to write it here. 20 00:01:38,250 --> 00:01:39,140 Okay. 21 00:01:39,750 --> 00:01:46,170 Uh, void void clears the screen screen. 22 00:01:48,090 --> 00:01:48,300 Yeah. 23 00:01:50,070 --> 00:01:53,130 And we're going to call the clear the screen. 24 00:01:55,580 --> 00:02:01,680 Clear the screen function here if the clear screen returns true. 25 00:02:01,700 --> 00:02:07,790 So in most cases, this function is expected to be used to print a single message. 26 00:02:07,790 --> 00:02:15,230 But occasionally the user may want to have the screen cleared first, say for the first message or after 27 00:02:15,230 --> 00:02:17,820 a predetermined count of lines. 28 00:02:17,840 --> 00:02:26,330 So to accommodate this use of this function, the clear screen parameter is given the default value 29 00:02:26,330 --> 00:02:33,610 of false here, but the color still has the option option of passing a value here. 30 00:02:33,620 --> 00:02:45,560 So now we're going to print the message here, Kay, like this print message here and and the line. 31 00:02:45,950 --> 00:02:58,070 And in the main function, let's call this log message function here and write our message first message 32 00:02:58,070 --> 00:02:58,610 here. 33 00:03:01,630 --> 00:03:04,300 And then we're going to pass the through here. 34 00:03:07,170 --> 00:03:10,080 And let's create another message here. 35 00:03:10,110 --> 00:03:18,750 This is the second message here without the without the second parameter bool parameter. 36 00:03:19,020 --> 00:03:25,680 As you can see, if you made this differently, like if we delayed this, as you can see, this message 37 00:03:25,680 --> 00:03:34,770 gives error because the compiler knows if we don't have the second parameter, then the full clear screen 38 00:03:34,770 --> 00:03:39,320 has to be false and we're going to like abstract virtual. 39 00:03:39,540 --> 00:03:42,630 We're going to have the virtual seven second parameter. 40 00:03:43,140 --> 00:03:46,410 If you call that like the real world applications here. 41 00:03:46,410 --> 00:03:47,010 So. 42 00:03:48,560 --> 00:03:48,920 Here. 43 00:03:48,920 --> 00:03:50,510 We're going to add another. 44 00:03:50,600 --> 00:03:52,250 We're going to create a pool here. 45 00:03:52,370 --> 00:03:56,540 So we're going to pass the user decision. 46 00:03:57,440 --> 00:03:59,240 And here. 47 00:04:00,800 --> 00:04:06,020 We're going to hear, for example, it's the you let's make the user decision. 48 00:04:07,160 --> 00:04:07,910 True. 49 00:04:08,210 --> 00:04:10,490 And we're going to log message here. 50 00:04:10,670 --> 00:04:12,980 Log message that third. 51 00:04:16,770 --> 00:04:24,240 Sir, the message here and we're going to pass the user decision as the variable here. 52 00:04:24,720 --> 00:04:25,770 That's okay. 53 00:04:26,250 --> 00:04:27,210 So. 54 00:04:28,460 --> 00:04:33,730 Not that the default values occur in the function, not in the function prototype here. 55 00:04:33,740 --> 00:04:42,680 So if the log message function is declared in a header file, the prototype here should be like like 56 00:04:42,680 --> 00:04:43,700 the external. 57 00:04:43,730 --> 00:04:45,510 Here we're going to have the extend. 58 00:04:45,560 --> 00:04:51,260 And without this braces here, we just have to write the parameters of our function. 59 00:04:51,260 --> 00:04:57,170 So if we call this function with X, then as you can see here, we're going to get the error here, 60 00:04:57,170 --> 00:04:58,670 but let's delete it. 61 00:04:59,800 --> 00:05:00,060 Oops. 62 00:05:00,130 --> 00:05:01,960 Uh, what's the problem here? 63 00:05:02,530 --> 00:05:03,760 We have the. 64 00:05:05,260 --> 00:05:06,200 Clear the screen. 65 00:05:06,230 --> 00:05:08,650 Yeah, We have to make it. 66 00:05:09,530 --> 00:05:11,120 I'm right here. 67 00:05:25,380 --> 00:05:25,650 Here. 68 00:05:25,650 --> 00:05:31,450 We're going to comment this up because this is the program of Lex lecture. 69 00:05:31,470 --> 00:05:37,100 And as you can see, the compiler showed the tells that we have the problem here. 70 00:05:37,110 --> 00:05:43,610 And we're going to firstly on the find the reference to clear the screen here. 71 00:05:43,620 --> 00:05:49,890 So now we just we're going to know we're not going to using this function for now. 72 00:05:51,450 --> 00:05:52,800 And we're going to delete that. 73 00:05:52,800 --> 00:05:56,320 And as you can see, we show the message on it here. 74 00:05:56,340 --> 00:05:57,390 So. 75 00:05:58,430 --> 00:06:01,820 Let's play this as well, like this here. 76 00:06:01,940 --> 00:06:08,150 And as you can see here, the first message, second message and third message printed here. 77 00:06:08,150 --> 00:06:14,250 And as you can see, the second in the 10th line, we didn't enter the second parameter. 78 00:06:14,270 --> 00:06:20,240 That's why the second, if we don't enter the second parameter, the compiler expects us that the second 79 00:06:20,240 --> 00:06:22,600 parameter is false here. 80 00:06:22,610 --> 00:06:30,200 So if we don't enter the second parameter, the second parameter will be automatically taken as false 81 00:06:30,200 --> 00:06:30,650 here. 82 00:06:30,680 --> 00:06:40,250 So actually you can treat the each parameter with the default value as representing the separate overload 83 00:06:40,250 --> 00:06:41,240 of the function. 84 00:06:41,390 --> 00:06:50,550 So conceptually here the log message function should be treated as two functions. 85 00:06:50,570 --> 00:06:58,640 As I said earlier, so if you if you define a log message function that has just a constant string parameter 86 00:06:58,640 --> 00:07:04,470 here, then the compiler will not know whether to call the function or the version. 87 00:07:04,490 --> 00:07:10,010 The clear the screen is given a default value of false here.