1
00:00:00,060 --> 00:00:03,630
It just scarred static variable and static functions.

2
00:00:03,720 --> 00:00:09,510
So it's very interesting topic in C++ if you are looking at static member variables.

3
00:00:09,870 --> 00:00:15,890
So we will be using a keyword like static to declare the static variable or static friendship between

4
00:00:15,930 --> 00:00:17,220
declared inside class.

5
00:00:17,520 --> 00:00:21,090
So what does the use of static variables or static functions?

6
00:00:21,720 --> 00:00:28,500
So static remember, variables are the member variables that belongs to the class rather than the object

7
00:00:28,500 --> 00:00:29,280
of that class.

8
00:00:29,670 --> 00:00:36,390
So it will be a variable which is dedicated to that class, which means that the value of that object

9
00:00:36,600 --> 00:00:42,870
or that particular variable will be always constant, constant in the sense, if I'm trying to create

10
00:00:42,870 --> 00:00:46,490
an object of a class and I'm trying to create that variable.

11
00:00:46,560 --> 00:00:52,890
It will be common across all the classes, not all the classes for all the objects created across that

12
00:00:52,890 --> 00:00:53,430
class.

13
00:00:53,880 --> 00:01:00,600
So only one instance of that variable will be created no matter how many objects of the same class at

14
00:01:00,600 --> 00:01:01,030
later.

15
00:01:01,140 --> 00:01:08,010
So if I have 10 objects, I'll pick last name Class E then and I'm declaring one static variable.

16
00:01:08,010 --> 00:01:10,920
Only one static variable will be created.

17
00:01:10,950 --> 00:01:13,950
OK, let the static variable will be distance.

18
00:01:14,100 --> 00:01:14,520
OK.

19
00:01:14,700 --> 00:01:18,720
That will be the name of that variable released and static int distance.

20
00:01:18,730 --> 00:01:22,830
That is that of how you create that static variable on a static function.

21
00:01:23,040 --> 00:01:29,190
So what would happen if I'm creating multiple objects of that pass, even if I'm creating 10 objects

22
00:01:29,190 --> 00:01:35,850
of the class like object or an object to object to two object 10 that all the variables inside objects

23
00:01:35,880 --> 00:01:38,100
named distance will be the same.

24
00:01:38,250 --> 00:01:40,470
So how are you going to understand that?

25
00:01:40,620 --> 00:01:42,780
It can be the by seeing the.

26
00:01:43,170 --> 00:01:46,740
So let's see a demo to understand this concept.

27
00:01:47,100 --> 00:01:50,010
So let's move to the static program here again.

28
00:01:50,020 --> 00:01:54,950
See, I have created a class named box and you have a static object.

29
00:01:55,180 --> 00:01:56,780
This is our static object.

30
00:01:56,790 --> 00:01:59,850
So we had, OK, I'm sticking it out here, constructor.

31
00:02:00,000 --> 00:02:01,570
We will be covering shortly.

32
00:02:01,590 --> 00:02:09,180
So constructor will be setting the values of this meeting was ill be and it's it will be length and

33
00:02:09,180 --> 00:02:09,420
height.

34
00:02:09,630 --> 00:02:13,400
So you will be able to calculate calculate the volume of a box.

35
00:02:13,410 --> 00:02:18,410
It's used by Ellen to be in the edge length interpreted into how it will calculate the warning.

36
00:02:18,450 --> 00:02:21,570
So we have a function for calculating the volume of the box.

37
00:02:21,960 --> 00:02:28,110
So this glass box is about all, about connected to a box and we have a box which is having a length,

38
00:02:28,110 --> 00:02:29,640
bright and height.

39
00:02:29,850 --> 00:02:34,530
And you will be calculating you'll be able to calculate the volume of the box.

40
00:02:34,830 --> 00:02:42,670
So here we have the variables created for that length, but eight which are private and you have the

41
00:02:42,690 --> 00:02:46,590
constructor to get to give the values of the box.

42
00:02:46,740 --> 00:02:52,890
So it will be debris equal to two point zero number B equal to two point zero eight equal to 2.0.

43
00:02:53,070 --> 00:02:56,610
So length would be too, but it will be two and three b two.

44
00:02:56,820 --> 00:03:04,020
Then I am assigning this value of length equal to L and this value bracket equal to be and this value

45
00:03:04,590 --> 00:03:05,580
will be each.

46
00:03:05,940 --> 00:03:09,390
So the values of land, Brent and height will become two two.

47
00:03:09,390 --> 00:03:12,720
And you know what we are doing inside this constructor.

48
00:03:12,840 --> 00:03:18,030
I have this object count as a counter variable created but just static.

49
00:03:18,060 --> 00:03:25,320
You have been taught that if you include a static keyword in front of any variable or declaration inside

50
00:03:25,320 --> 00:03:27,750
a glass, that will become a static variable.

51
00:03:27,870 --> 00:03:28,900
So what would happen?

52
00:03:28,920 --> 00:03:31,800
I'm calling the get go on function.

53
00:03:32,100 --> 00:03:35,350
This is our step function, but this is our static.

54
00:03:35,400 --> 00:03:38,580
So we have a static function and a static variable out here.

55
00:03:38,820 --> 00:03:44,070
Now I'm trying to increment the object count or that variable count.

56
00:03:44,100 --> 00:03:48,060
So each time that object is created, this column, this increment.

57
00:03:48,420 --> 00:03:50,850
So let's see how many object will be creating.

58
00:03:51,030 --> 00:03:58,390
So we created a static number object count equal to zero plus the count will be zero, then going within

59
00:03:59,130 --> 00:04:02,040
into main function initial stage count.

60
00:04:02,130 --> 00:04:04,500
You will be showing the false start.

61
00:04:04,500 --> 00:04:05,150
Get done.

62
00:04:05,250 --> 00:04:07,860
So how are you going to access the static variable?

63
00:04:08,130 --> 00:04:10,800
You have to use the syntax you have to use.

64
00:04:11,160 --> 00:04:16,590
You have to use this update to score a resolution on Theta.

65
00:04:16,830 --> 00:04:17,310
OK.

66
00:04:17,490 --> 00:04:18,600
Like four cards.

67
00:04:19,320 --> 00:04:19,710
OK.

68
00:04:20,100 --> 00:04:24,720
How you can create score resolution once you do this, and again, you add this.

69
00:04:24,930 --> 00:04:27,530
So this will be the SCOP resolution operator.

70
00:04:27,600 --> 00:04:34,290
Why we are using this to access the that big meeting was so static and shoots so banks are to go down.

71
00:04:34,380 --> 00:04:36,540
We are accessing that function.

72
00:04:36,660 --> 00:04:37,540
What will happen?

73
00:04:37,590 --> 00:04:39,580
We have the object can be equal to zero.

74
00:04:39,600 --> 00:04:42,310
So blocks that count return object count.

75
00:04:42,330 --> 00:04:43,810
What is the value of object count?

76
00:04:43,830 --> 00:04:44,660
It will be zero.

77
00:04:44,670 --> 00:04:46,160
No box one.

78
00:04:46,440 --> 00:04:50,430
We will be passing the values three point three one point twenty one point five.

79
00:04:50,640 --> 00:04:52,590
That is box one and Box two.

80
00:04:52,620 --> 00:04:57,210
OK, what happens when we have Box one created again?

81
00:04:57,240 --> 00:04:59,880
It will be going to the constructor.

82
00:05:00,020 --> 00:05:03,710
All of that glass glass, we've been preventing the object count.

83
00:05:04,110 --> 00:05:07,010
OK, then you will be incriminating.

84
00:05:07,010 --> 00:05:10,930
The currently the value of object carries obviously count is zero.

85
00:05:10,940 --> 00:05:12,350
It is incremental to one.

86
00:05:12,650 --> 00:05:18,430
So when this object was created, it will become Object County Court to it too.

87
00:05:18,890 --> 00:05:24,450
And when this glass, this object is created, object count will be becoming three.

88
00:05:25,430 --> 00:05:27,590
So why are you not expecting this behavior?

89
00:05:27,680 --> 00:05:33,200
That is what you need to understand in this program, because that variable object down to static.

90
00:05:33,230 --> 00:05:40,730
So even if different objects are created, the value is not initialized to zero each time because it

91
00:05:40,730 --> 00:05:42,350
will maintain only one copy.

92
00:05:42,470 --> 00:05:46,010
So all these objects are accessing that same medium.

93
00:05:46,310 --> 00:05:53,660
But if you create an orange static variable, what happens is all the objects will have different variables.

94
00:05:53,930 --> 00:05:56,810
It will not be blinding to a single variable.

95
00:05:56,990 --> 00:06:02,180
So that system or these static variables, I didn't include this example.

96
00:06:02,180 --> 00:06:09,980
So that's why I wanted to point out how the static object or static variable will be created in this

97
00:06:09,980 --> 00:06:13,320
X-number of a cube instead of box.

98
00:06:13,340 --> 00:06:18,590
Here you can see a few, and it's having sight equal to five side equal bay density.

99
00:06:19,040 --> 00:06:27,940
And so each time you create that variable or to object for a glass named cube and it's having its non

100
00:06:27,950 --> 00:06:32,210
static variable part say three different variables would be created.

101
00:06:32,780 --> 00:06:38,610
And if you have created one a variable called object down, which is static.

102
00:06:39,470 --> 00:06:41,780
This will be common to all three objects.

103
00:06:41,780 --> 00:06:46,040
So Cube one, you may be having a pointing to the same object.

104
00:06:46,460 --> 00:06:48,530
This will also binding to the same object.

105
00:06:48,560 --> 00:06:50,930
This will also be binding to the same object.

106
00:06:51,050 --> 00:06:56,480
So that's one point which you will need to remember when you study about the static variable.
