1
00:00:03,120 --> 00:00:08,430
Hello everyone in this session we will learn more about constructors in the last session.

2
00:00:08,430 --> 00:00:11,900
We learned what our constructors and how they are called.

3
00:00:11,910 --> 00:00:13,430
When we create an object.

4
00:00:13,650 --> 00:00:19,620
So we also learn that as soon as we create a class our default constructor is created and we can use

5
00:00:19,620 --> 00:00:25,710
the default constructor for initializing the object we can create our own constructor also.

6
00:00:25,830 --> 00:00:31,350
And as soon as we create our own constructor and build constructor is not visible to us anymore.

7
00:00:32,060 --> 00:00:32,680
Okay.

8
00:00:32,850 --> 00:00:43,660
So what happened is as soon as we create our class as soon as we create our class we get a few functions

9
00:00:43,660 --> 00:00:56,130
for free we will get a few functions for free so no one is default constructor.

10
00:00:56,160 --> 00:01:04,970
The second function that we will get for fee is called copy constructor.

11
00:01:05,080 --> 00:01:07,210
The third one is copy assignment operator

12
00:01:12,320 --> 00:01:16,850
and the fourth one is called our district that

13
00:01:21,040 --> 00:01:21,500
okay.

14
00:01:21,560 --> 00:01:27,860
So as soon as we create a class we will get a few functions for free.

15
00:01:27,860 --> 00:01:32,820
We have already started about a default constructor and what it does in this video.

16
00:01:32,880 --> 00:01:39,020
Our main focus will be on copy constructor and in the next videos we will learn about these two copy

17
00:01:39,020 --> 00:01:41,040
assignment operator and district.

18
00:01:41,210 --> 00:01:45,510
Okay so let's start to this topic which is a copy constructor.

19
00:01:45,650 --> 00:01:47,150
So what is a copy constructor.

20
00:01:47,150 --> 00:01:54,920
Let us first understand with the help of an example let us create two objects a student s one and let's

21
00:01:54,920 --> 00:01:59,120
say that all somebody stone ages 10 and somebody is hundred.

22
00:01:59,120 --> 00:02:00,580
So what will happen.

23
00:02:00,620 --> 00:02:04,190
Batman tries to construct a little bit called okay.

24
00:02:04,310 --> 00:02:07,530
Now let us create that object.

25
00:02:07,530 --> 00:02:18,900
Student as to in this case default constructor will be called Okay now I let him Our aim is very simple.

26
00:02:18,910 --> 00:02:21,890
I want to copy the value of S1 and to S2.

27
00:02:22,240 --> 00:02:22,850
Okay.

28
00:02:23,050 --> 00:02:24,670
So our aim is very simple.

29
00:02:24,730 --> 00:02:27,020
Copy the value of S went into S2.

30
00:02:27,070 --> 00:02:35,280
So what I want is is to age should be 10 and as to the number should be a hundred.

31
00:02:35,420 --> 00:02:37,800
Okay so how can we do this.

32
00:02:37,880 --> 00:02:49,540
So there is very simple we we will do like this is to dot set age and we will give input as as one dart

33
00:02:49,810 --> 00:02:50,440
get age

34
00:02:54,210 --> 00:03:04,740
and similarly S2 doctoral but is S1 daughter number.

35
00:03:04,990 --> 00:03:15,430
See if we will write as to what age is S1 Dark Age this line is wrong way because age is a private field

36
00:03:16,580 --> 00:03:22,010
age is a private field so if we want to do something if we want to do something with age we have to

37
00:03:22,010 --> 00:03:24,950
use public functions set age and get age.

38
00:03:24,950 --> 00:03:26,630
Okay rule number is public.

39
00:03:26,720 --> 00:03:29,840
So it will work fine okay.

40
00:03:29,870 --> 00:03:36,440
So if I want to copy the value of S1 into S2 I have to write these two lines I have to write these two

41
00:03:36,440 --> 00:03:40,510
lines explicitly okay.

42
00:03:41,420 --> 00:03:44,720
So we do not need to do this work explicitly.

43
00:03:44,720 --> 00:03:50,900
We have a constructor for doing this work and that constructor is called a copy constructor okay.

44
00:03:51,010 --> 00:04:02,050
So what copy constructor does is it creates the copy it creates an object which is copy of other object

45
00:04:02,490 --> 00:04:07,960
which is copy of either object.

46
00:04:07,990 --> 00:04:10,320
So this is the work of a copy concept.

47
00:04:11,050 --> 00:04:13,210
So let's let's take an example

48
00:04:16,330 --> 00:04:22,690
let's create an object first student S1 ages 10 the numbers ended.

49
00:04:22,770 --> 00:04:29,120
Now I want to make a copy of student S1 so the syntax is very simple.

50
00:04:29,190 --> 00:04:34,870
Student S2 and we will give S1 s better.

51
00:04:36,280 --> 00:04:42,370
Okay so what will happen the properties of the values of S1 will get copied into S2.

52
00:04:43,210 --> 00:04:50,760
So in this case better made price to constructively regard which we have created in the last radios

53
00:04:51,300 --> 00:04:58,790
and in this case copy constructor will be called Okay which will copy the value off as 1 and 2 S2.

54
00:04:58,790 --> 00:05:01,580
So how would this line will be interpreted.

55
00:05:01,580 --> 00:05:11,030
This line will internally look like this as one dot sorry is to not have a function student and input

56
00:05:11,030 --> 00:05:13,800
will be as one parameter will be S1.

57
00:05:14,040 --> 00:05:20,950
Okay so S1 is of type student s and is a barometer of type student.

58
00:05:21,140 --> 00:05:29,660
Now we have not created any constructor which takes one argument of type student as input Okay we have

59
00:05:29,660 --> 00:05:34,820
not made any constructor which takes one argument of type student but we are able to use it.

60
00:05:35,060 --> 00:05:41,280
How because as soon as we create a class copy construct base also created.

61
00:05:41,490 --> 00:05:44,370
Okay so what will the effect of these two lines.

62
00:05:44,640 --> 00:05:46,900
So the effect of this line is very simple.

63
00:05:48,260 --> 00:05:54,170
Age will be 10 and rule number will be entered.

64
00:05:54,290 --> 00:06:08,800
This is S1 and the effect of this line ages then rule number is hundred and this is Student 2 Okay now

65
00:06:08,800 --> 00:06:12,190
one thing here is since copy construct basic concept.

66
00:06:12,370 --> 00:06:15,330
It will be called only at the time of the creation of the object.

67
00:06:16,600 --> 00:06:18,310
Okay now let's see in called

68
00:06:28,020 --> 00:06:29,610
let's make an object string.

69
00:06:29,610 --> 00:06:34,160
That's 1 8 just in really embodies and read.

70
00:06:34,270 --> 00:06:37,210
So copy barometer based constructor will be guarded

71
00:06:43,280 --> 00:06:43,610
okay.

72
00:06:43,620 --> 00:06:53,620
We have created this Panama imitates constructor and let's spend something so we'll see out S1

73
00:06:56,490 --> 00:06:57,940
and let's call display function.

74
00:06:57,980 --> 00:07:01,560
So S1 dart display okay.

75
00:07:01,730 --> 00:07:13,690
So now make an object this object will be the copy of s an object and let's print this object onto the

76
00:07:13,690 --> 00:07:14,500
student as to

77
00:07:19,750 --> 00:07:21,650
as to not display

78
00:07:25,790 --> 00:07:29,040
so in this lane copy construct a little bit cold.

79
00:07:29,120 --> 00:07:31,780
And this court begins to produce in bold constructed.

80
00:07:32,350 --> 00:07:42,840
OK so this better imitates construct that is user defined Vermeer discussed it it is not so this bad

81
00:07:42,840 --> 00:07:46,230
imitates concept but is not given by class.

82
00:07:46,260 --> 00:07:49,290
We created this constructor Okay so user defined

83
00:07:52,510 --> 00:07:54,580
Okay so now let us turn this file

84
00:07:58,030 --> 00:08:03,460
so the value of this is getting printed paramedics construct based called construct with regard the

85
00:08:03,460 --> 00:08:08,150
value of age for student s on the stand and for us to do is also ten hundred and hundred the value from

86
00:08:08,160 --> 00:08:09,920
Lumberton also same.

87
00:08:10,030 --> 00:08:16,180
So one thing here is so one thing to note here is there is no constructor called a message for object

88
00:08:16,290 --> 00:08:22,420
as true because for us to copy constructor is called and we have not made our own copy construct but

89
00:08:22,660 --> 00:08:29,350
we are using the intended copy sector and in that inbuilt copy construct that there is no see out message.

90
00:08:29,350 --> 00:08:36,370
So that's why it see our message will appear for object as to so in this way we can use copy constructor

91
00:08:36,370 --> 00:08:38,050
to create copy of the object.

92
00:08:38,670 --> 00:08:39,230
Okay.

93
00:08:39,400 --> 00:08:43,950
So in this way we can use copy constructor to create copies of the object.

94
00:08:43,960 --> 00:08:47,230
Now here we have created objects statically.

95
00:08:47,260 --> 00:08:53,040
Now let's see what lesson it takes for creating objects creating copy of objects dynamically.

96
00:08:53,080 --> 00:08:55,720
So let us first create a object.

97
00:08:55,720 --> 00:09:06,350
So student history is new student and let's call betterment based constructor ages 20 and almost 200

98
00:09:08,800 --> 00:09:09,370
okay.

99
00:09:09,440 --> 00:09:11,480
Now let's bring those three

100
00:09:16,100 --> 00:09:17,220
as three add or display

101
00:09:20,960 --> 00:09:21,230
okay.

102
00:09:21,230 --> 00:09:33,180
Now let us make copies of s.t. so student as for S3 now is it right.

103
00:09:33,300 --> 00:09:35,230
Is this index right.

104
00:09:35,250 --> 00:09:36,070
No it is wrong.

105
00:09:36,070 --> 00:09:36,360
Why.

106
00:09:36,370 --> 00:09:39,980
Because Estes a pointer and I want values.

107
00:09:40,290 --> 00:09:42,530
So we have to use be defense operator.

108
00:09:43,130 --> 00:09:45,890
Now student s what is the copy of S3.

109
00:09:46,590 --> 00:10:00,450
Okay now we can create dynamic copy also how so a student is five is no student and start history.

110
00:10:00,520 --> 00:10:01,030
Okay.

111
00:10:01,190 --> 00:10:07,480
We have dos the defense operated and what if we want to create the copy of static object so the index

112
00:10:07,480 --> 00:10:19,800
will be student at 6 is no student and start to go object S1 Okay so this is how the copy constructor

113
00:10:19,800 --> 00:10:20,760
works.

114
00:10:20,760 --> 00:10:26,880
So a student S4 is the copy of S3 S5 is the copy of S3.

115
00:10:26,970 --> 00:10:31,140
Okay so we are copying the values of S3 into S5.

116
00:10:31,170 --> 00:10:36,140
Similarly the values of S1 is being copied in two S6.

117
00:10:36,360 --> 00:10:38,280
So this is all about copy constructor

118
00:10:43,750 --> 00:10:43,980
okay.

119
00:10:44,000 --> 00:10:49,430
So now we know what is a default constructor and what is a copy constructor.

120
00:10:49,460 --> 00:10:54,040
Next we do we will learn about copy assignment operator okay.

121
00:10:54,080 --> 00:10:54,460
Thank you.
