WEBVTT

00:01.150 --> 00:09.070
C plus plus 11 introduced a mechanism for declaring that a variable's type should be determined from

00:09.070 --> 00:14.980
the data it is initialized with, and that is the auto keyword here.

00:15.310 --> 00:23.650
So this is a minor confusion here because the prior C plus plus 11 prior to C plus plus 11, the auto

00:23.650 --> 00:27.010
key was used to declare the automatic variables.

00:27.040 --> 00:32.110
That is the variables that are automatically allocated on the stack in a function.

00:32.110 --> 00:40.240
So other than variables declared at a file scope or a static, are the other variables in this course

00:40.240 --> 00:46.870
so far have been automatic variables, and automatic variables are the most widely used storage class.

00:47.470 --> 00:56.590
So since it was optional and applicable to most variables, the auto keyword was rarely used in C plus

00:56.590 --> 00:57.210
plus.

00:57.220 --> 01:00.710
So the C plus plus 11 took advantage of this.

01:00.710 --> 01:07.820
Remove the old meaning and gave the author the whole new meaning here.

01:07.820 --> 01:15.890
So if you're compiling all C plus plus code with the C plus plus 11 compiler and that old code uses

01:15.920 --> 01:24.140
auto, so you will get errors because the new compiler will assume auto will be used with the variables

01:24.140 --> 01:27.230
with no specified type.

01:27.230 --> 01:28.280
So.

01:29.200 --> 01:34.170
If this happens, simply search and delete each instance of auto.

01:34.180 --> 01:38.530
So it was redundant in C plus plus prior to C plus plus 11.

01:38.530 --> 01:43.210
And there was a little reason for developers to use it here.

01:43.240 --> 01:50.710
The auto keyword means that the compiler should create a variable with the type of the data that is

01:50.710 --> 01:51.670
assigned to it.

01:51.670 --> 01:55.230
So the variable can only have a single type.

01:55.240 --> 02:00.190
The type the compiler decides is a type it needs for the data assigned to it.

02:00.370 --> 02:06.670
So and you cannot use the variables elsewhere to hold data of a different type because the compiler

02:06.670 --> 02:10.270
needs to determine the type from an initializer.

02:10.270 --> 02:16.300
And it means that all auto variables must be initialized.

02:17.200 --> 02:17.920
Now.

02:18.190 --> 02:21.150
Now, I want to do some examples here.

02:21.160 --> 02:27.880
So let's create an auto variables, which I will explain all of these auto variables later and add comments

02:27.880 --> 02:28.720
to it.

02:29.380 --> 02:34.480
For example, 42 auto be 42.

02:36.260 --> 02:36.830
Here.

02:36.860 --> 02:44.060
Auto c 42 lx here auto d here.

02:44.840 --> 02:50.150
Um 1.11.0 f auto.

02:51.120 --> 02:51.960
E here.

02:53.490 --> 02:55.590
1.0.

02:57.000 --> 02:57.900
Auto.

02:59.690 --> 03:00.740
If here.

03:02.510 --> 03:04.850
Uh, if it's going to be character.

03:10.760 --> 03:11.180
Here.

03:14.960 --> 03:15.950
And auto.

03:18.590 --> 03:19.130
Here.

03:19.160 --> 03:19.640
True.

03:22.160 --> 03:22.940
Here.

03:23.510 --> 03:28.630
Now I want to add, um, variables after it.

03:28.640 --> 03:40.280
So this is the integer we created integer type because we assigned to just an integer and here we created

03:40.280 --> 03:43.790
the long type, just the long integer.

03:44.390 --> 03:47.780
So we created long, long integer.

03:48.880 --> 03:49.420
Here.

03:49.420 --> 03:51.510
We created the float.

03:52.370 --> 03:53.630
Here.

03:54.620 --> 04:03.890
Double note that there is no syntax to specify that an integer value is a single byte or two byte,

04:03.890 --> 04:11.240
so you cannot create an unsigned character variables or short variables this way.

04:11.880 --> 04:15.010
Uh, and here we created the character.

04:15.020 --> 04:17.300
Just a usual normal standard character.

04:18.410 --> 04:21.410
And here we created the bull here.

04:22.560 --> 04:27.630
So this is a tribal use of the auto keyword.

04:27.630 --> 04:36.690
You should some sometimes you create this auto keyword with this and the compiler will assign the type

04:36.690 --> 04:39.330
of this variable automatically.

04:39.330 --> 04:44.250
So now I want to create another example to show you how this happens.

04:44.250 --> 04:48.870
And here this things might might get confusing.

04:48.870 --> 04:56.940
So don't worry if you don't know about the tuple or vectors here, which you will learn in later lectures.

04:56.940 --> 05:04.770
So now I want to create a vector that will take two, uh, one tuple, uh, in the tuple we're going

05:04.770 --> 05:06.840
to have string and integer.

05:08.110 --> 05:10.180
Here, we're going to create the vector.

05:10.360 --> 05:13.180
As you can see here, vector is not a built in type.

05:13.180 --> 05:18.910
So we have to import from the import class of vector to use it.

05:18.910 --> 05:23.380
And as you can see here, the compiler created a include vector here.

05:24.460 --> 05:26.830
The vector here tuple.

05:28.350 --> 05:30.720
String integer here.

05:30.750 --> 05:37.800
So as you can see, we have a tuple and we need to import the string here.

05:39.820 --> 05:43.210
And here we're going to name it my cars.

05:44.180 --> 05:50.510
Uh, as you can see, we got an error because we didn't actually included the tuple here.

05:50.510 --> 05:54.620
So that's why we're going to include include.

05:55.320 --> 06:01.290
Couple here, as you can see here, our error gone away and then.

06:02.700 --> 06:03.300
Here.

06:03.660 --> 06:08.730
We're going to add variables to my car's vector.

06:08.760 --> 06:10.260
Here, my cars.

06:10.260 --> 06:11.800
I will explain all of these codes here.

06:11.820 --> 06:12.750
Don't worry.

06:13.350 --> 06:19.860
My car's pushback back make topple and we're going to pass the.

06:21.930 --> 06:26.960
For example, let's name some car BMW and its year here.

06:27.270 --> 06:32.280
As you can see, the first is string and the second parameter is integer.

06:32.280 --> 06:38.250
So let's input our the date of production.

06:38.580 --> 06:44.120
The year of production of our car, for example, 2001.

06:44.130 --> 06:45.420
My cars.

06:45.450 --> 06:47.820
Or let's make a model of it.

06:47.820 --> 06:49.500
So make it look nicer.

06:52.110 --> 06:55.080
5/5 series here.

06:55.110 --> 06:58.070
My cars push back.

06:58.770 --> 07:00.120
Make Topple.

07:00.810 --> 07:02.010
The fourth.

07:03.450 --> 07:04.290
Uh.

07:05.690 --> 07:06.380
Mustang.

07:06.770 --> 07:07.820
Mustang.

07:07.910 --> 07:08.750
Here.

07:10.040 --> 07:11.510
1989.

07:12.320 --> 07:13.580
My cars.

07:14.560 --> 07:16.330
The pushback.

07:17.680 --> 07:18.970
Make a couple.

07:20.960 --> 07:23.150
Uh, Volkswagen Golf here.

07:23.150 --> 07:25.370
2010.

07:26.680 --> 07:27.580
My car.

07:27.580 --> 07:28.150
Start.

07:28.150 --> 07:29.170
Push back.

07:29.870 --> 07:30.690
Make.

07:30.710 --> 07:31.340
Make.

07:31.380 --> 07:32.180
Topple.

07:33.400 --> 07:34.060
Uh, here.

07:34.060 --> 07:37.990
We're going to input the Land Rover.

07:38.500 --> 07:40.270
Land Rover.

07:41.380 --> 07:44.440
Land Rover here.

07:46.190 --> 07:49.610
2015 here.

07:50.030 --> 07:59.720
Now we're going to create a for loop here for here, Tupple string integer here.

07:59.990 --> 08:03.320
It's going to be like my vehicles.

08:06.000 --> 08:08.040
Here and then.

08:09.360 --> 08:10.470
My cars.

08:10.470 --> 08:11.700
We will iterate.

08:11.730 --> 08:17.550
My cars one by one here, and then we're going to print it out here.

08:17.580 --> 08:18.570
C out.

08:19.410 --> 08:20.130
C out.

08:20.130 --> 08:26.010
As you can see, we cannot use C out because we have to use a include STD.

08:27.930 --> 08:28.350
Here.

08:30.040 --> 08:32.250
Input output stream and see.

08:33.910 --> 08:35.950
Get here.

08:41.490 --> 08:42.150
Get.

08:42.940 --> 08:44.440
My vehicles.

08:45.870 --> 08:46.230
Here.

08:49.440 --> 08:50.100
Get.

08:50.930 --> 08:51.700
One.

08:51.710 --> 08:53.260
I will explain all of these codes.

08:53.270 --> 08:53.780
Don't worry.

08:53.780 --> 08:54.380
Here.

08:55.670 --> 08:58.040
And get one.

08:58.430 --> 09:00.530
My vehicles.

09:02.590 --> 09:04.060
And end line.

09:05.600 --> 09:07.700
And let's run our code here.

09:11.510 --> 09:12.020
Okay.

09:14.900 --> 09:17.840
Make it look nice and print it out again.

09:18.770 --> 09:25.100
So this code, as you can see, this is our okay, make it run it again.

09:25.100 --> 09:36.830
So here, as you can see here, this code uses the vector container here to as you know, we haven't

09:36.830 --> 09:39.920
used vector or tuples, so don't worry about them.

09:40.430 --> 09:46.280
You will learn in next lectures about vectors and tuples and other technologies in C plus plus here.

09:46.280 --> 09:51.020
But just keep in mind that you will learn it and don't panic here.

09:51.440 --> 09:58.490
So, uh, here the vector stores two value items using this tuple.

09:59.670 --> 10:01.800
So the tuple class is simple.

10:01.830 --> 10:08.460
You declare a list of the types of items in the tuple object and the declaration between the angled

10:08.700 --> 10:09.870
braces here.

10:09.870 --> 10:18.060
So the tuple string integer declaration says that the object will hold a string and an integer.

10:18.060 --> 10:24.780
So in that order, the make tuple function here make tuple function here.

10:25.720 --> 10:34.540
Is provided by the C plus plus standard library and will create a tuple object containing two values.

10:34.540 --> 10:40.150
The first is a string and the second is integer.

10:40.330 --> 10:45.760
So the pushback function will put the item into the vector container.

10:45.760 --> 10:53.080
So after the for cost of the pushback function, the here the vehicles.

10:54.340 --> 11:03.070
The vehicle's variable will contain actually the my car's variable will contain four items and each

11:03.100 --> 11:11.590
in the four items we're going to have two variables and each one is tuple with the name and birth year.

11:11.770 --> 11:20.710
And here, as you can see, the range for loops throughout the container and on each loop assigns the

11:21.040 --> 11:27.580
my vehicle variable with the next item in the container of my cars.

11:27.580 --> 11:34.600
So the values in the tuple are printed to the console, as you can see here in this function.

11:35.770 --> 11:37.170
And for loop here.

11:37.170 --> 11:43.830
So an item in the tuple here is accessed using the get.

11:45.320 --> 11:48.920
Parameterized function from the tuple.

11:48.950 --> 11:52.010
Here, as you can see here, this is a get function.

11:52.280 --> 11:55.160
This get function belongs to tuple here.

11:55.820 --> 11:56.960
So.

11:59.430 --> 12:08.130
And here, as you can see here, the first we assigned zero to get the first object of this tuple and

12:08.130 --> 12:17.370
then a space here and then get one, uh, gets the year of item in the tuple.

12:17.370 --> 12:22.800
And the result of this code is this output here.

12:23.010 --> 12:30.690
So the next text has poor formatting because it does not take into account the length of the names.

12:30.690 --> 12:35.730
So this can be addresses using the manipulators in next lectures.

12:35.730 --> 12:38.490
So we're going to create here.

12:39.930 --> 12:44.190
Uh, take a look at the for loop here.

12:46.040 --> 12:48.560
So the type of the.

12:49.350 --> 12:54.450
My vehicles is tuple, string and integer.

12:54.450 --> 13:02.340
So this is fairly simple type and as you use the standard template more, you could end up with some

13:02.340 --> 13:06.600
complicated type, particularly when you use iterators.

13:06.600 --> 13:10.690
So this is where our tool becomes useful.

13:10.820 --> 13:13.560
The here we're going to create a code.

13:15.020 --> 13:17.580
Okay, so let's comment it out.

13:19.160 --> 13:19.640
Here.

13:22.740 --> 13:23.010
Oops.

13:25.110 --> 13:25.380
Here.

13:28.640 --> 13:29.510
Commented out.

13:31.020 --> 13:32.250
And here.

13:36.700 --> 13:37.420
For.

13:38.800 --> 13:41.140
Autonomy vehicles.

13:43.490 --> 13:48.920
Girls and my cars and see out.

13:51.260 --> 13:53.420
Get zero.

13:54.970 --> 13:58.120
From the my vehicles.

13:59.360 --> 14:01.670
Vehicles and.

14:04.010 --> 14:04.460
Here.

14:06.000 --> 14:12.480
Get one from the my vehicles here and end line.

14:14.490 --> 14:17.760
So here.

14:20.580 --> 14:23.340
This is where R2 becomes useful here.

14:23.340 --> 14:28.090
So this code is the same but easier to read.

14:28.110 --> 14:32.670
So the my vehicles variable is still typed.

14:33.270 --> 14:44.340
It has a tuple string integer, but auto means you do not have to explicitly code this in like this

14:44.340 --> 14:45.330
example here.

14:45.330 --> 14:50.220
So this is more readable code and more useful on this case here.
