There are situations when you have one or more parameters that have values that are so frequently used
that you want them to be treated as a default value for the parameter.
So while still having the option of allowing the color to provide a different value if necessary.
So to do this, you provide a default value in parameter parameter list of the definition here.
So let's, let's make the void here.
Make a new function named log message here.
First is const string here message.
Of course we have to include the string.
Okay.
Change string to.
Yeah, we have to.
Include.
String.
Okay.
And.
We have to.
Using namespace STD.
Stayed here.
And then we're going to create another bull here and bull clear screen.
And we're going to equal to false here.
As you can see, this is the first time we use the self initializing parameters in this course here.
So and we're going to add the if the clear screen is true, then clear the clear the screen here, which
we're going to write it here.
Okay.
Void, void.
Clear the screen screen.
Yeah.
And we're going to call the clear the screen.
Where the screen function here is the clear screen returns true.
So in most cases, this function is expected to be used to print a single message, but occasionally
the user may want to have the screen cleared first.
Say for the first message or after a predetermined count of lines.
So to accommodate this use of this function, the clear screen parameter is given the default value
of false here.
But the caller still has the option option of passing a value here.
So now we're going to print the message here.
Okay.
Like this print message here and end the line.
And in the main function, let's call this log message function here and write our message.
First message here.
And then we're going to pass the true here.
And let's create another message here.
This is the second message here.
Without the, uh, without the second parameter bool parameter here.
As you can see, if we made this differently, like if we delete this, as you can see, this message
gives error because the compiler knows if we don't have the second parameter, then the bool clear screen
has to be false and we're going to like abstract virtual.
We're going to have the virtual seven second parameter if we call that like the real world applications
here.
So.
Now here we're going to add another we're going to create a bool here.
So we're going to pass the user's decision.
And here.
We're going to here for, for example, let's, let's make the user decision, uh, true.
And we're going to the log message here.
Log message that third.
Third message here, and we're going to pass the user decision as the variable here.
Let's.
Okay.
So.
Notice that default values occur in the function, not in the function prototype here.
So if the log message function is declared in a header file, the prototype here should be like like
the extern here we're going to add the extern and without these braces here we just have to write the
parameters of our function.
So if we call this function with extern, as you can see here, we're going to get the error here,
but let's delete it.
Oops.
Uh, what's the problem here?
We have the.
Clear the screen.
Yeah.
We have to make it.
Under it here.
Here.
Are we going to comment this up?
Because this is the the program of next lecture.
And as you can see, the compiler showed the tells that we have the problem here and we're going to
firstly undefined reference to clear the screen here.
So now we just we are not we we're not going to using this function for now.
And we're going to delete that.
And as you can see, we show the message on it here.
So.
Let's delete this as well.
Like this here.
And as you can see here, the first message, second message and third message printed here.
And as you can see, the second in the 10th line, we didn't enter the second parameter.
That's why the second, if we don't enter the second parameter, the compiler expects us that the second
parameter is false here.
So if we don't enter the second parameter, the second parameter will be automatically taken as false
here.
So actually you can treat the each parameter with a default value as representing the separate overload
of the function.
So conceptually here the log message function should be treated as two functions as I said earlier.
So if you did, if you define a log message function that has just a const string parameter here, then
the compiler will not know whether to call the function or the version.
The clear the screen is given a default value of false here.