Okay.
In this lecture you will learn about the access controls in C++.
So this is the same code as our previous lecture, right?
But we will we're going to add some access controls and methods here.
So access controls, restrict class member access, public and private, or there are two major access
controls so anyone can access a public member, but only a class can access its private members.
So all struct members are public by default.
So private members play an important role in encapsulation.
So consider here for example, my date and time class.
So as it stands, the year member here can be accessed from anywhere.
So for both reading and writing.
So suppose you want to protect against the value of the year here being less than 2019, so you can
accomplish this in two steps.
You make your private and you require anyone using the class consumers to interact with the year.
Only each row strikes methods.
So, for example, let's make the.
Year.
Private beer.
And then we're going to add method here named Ops.
Yeah.
We're going to add the method.
Seth.
Yea.
We will add this set here with Poul because it will return us.
True or false?
And the set year will take an integer new year as a per parameter.
So for example, if New Year year less than 2019 then return false year and.
Then.
Here.
Because New Year's.
And the return.
True.
And we're going to add integer.
Integer set get here, which will return just an integer.
And so will return as the integer value of our year variable.
So let's add this integer.
Get near here.
And return year.
And as you can see here, we made a private integer year here.
So.
So let's I want to explain all of this codes again here.
As you can see here, we cannot use this anymore here.
So in order to use where we need to, for example, so actually, let's let this.
So if you want to print something on the screen, you need to use the here.
The variables here.
So first we declare the integer my year here and MD that get here.
So this get here will return you a value that will show you here declared is private member of the sale.
So.
As you can see here, we will declare it private here.
So in order to get this, we will make a function public for now.
So we need to make a public function here and we will define the private at the end of the code.
So if we define the private in top of the code, then.
There are other codes on the bottom here after private will make itself private as well.
So as you can see here, we cannot directly use here.
As you can see here, here is private member of my data time.
So we can use here because here is private here.
So we define private members at the end of the line here.
So we need to in order to get here, we need to use function this function here.
So here, here, here, here and that get here.
And we showed us the year here and let's change the year end date set here.
Let's set the year to.
For example, 2023.
And here they will get the urge.
And let's print our code here.
So as you can see here, we started here from zero because we didn't sign anything on it.
And then we assign 20, 23 to year.
And here let's actually assign something on it.
And date set here.
So we don't see zero here.
2019.
And that's right.
As you can see here, we got the result here and we successfully assigned 2019 integer on the on the
year variable here.
So let's try 2018 or, for example, 2016.
As you can see here, we got the zero because our if statement, as you can see here, returned false
and this code here did not execute it.
So the if statement is triggered and the the other course is not executed in this function.
So that's why we didn't assign anything on it.