1
00:00:00,940 --> 00:00:07,810
OK, so this will just be a short video on what I asked you to attempt in the last video, which was

2
00:00:07,810 --> 00:00:15,670
to take this template template memory function that you created and implement it in the other derived

3
00:00:15,670 --> 00:00:23,320
classes as well, and also attempt to combine it into the overall pie of polymorphic design by trying

4
00:00:23,320 --> 00:00:31,360
to incorporate it into the base class and have it be, you know, a kind of abstracted function that

5
00:00:31,360 --> 00:00:34,120
needs to be implemented in these other drive classes.

6
00:00:34,120 --> 00:00:36,310
So let's go ahead and try then.

7
00:00:38,120 --> 00:00:39,620
So we already have it here in triangle.

8
00:00:40,370 --> 00:00:45,590
All I really need to do is copy and paste this for the base classes, so I'm going to go ahead and go

9
00:00:45,590 --> 00:00:46,700
into a circle.

10
00:00:47,510 --> 00:00:48,640
I'm going to assume in a little bit.

11
00:00:48,650 --> 00:00:54,620
I noticed last year a little bit zoomed out, so hopefully you listen too hard for you to see it, but

12
00:00:54,620 --> 00:00:57,140
I'm going to go ahead to the rectangle here.

13
00:00:59,180 --> 00:01:05,240
Assuming a bit there to pace that as well, so we can just paste it right because it's called ambiguously.

14
00:01:05,330 --> 00:01:06,230
It's bigger shape.

15
00:01:06,830 --> 00:01:11,960
This is an ambiguous argument, you know, as far as the data type, and then we're just calling area

16
00:01:11,960 --> 00:01:14,220
on whatever this shape may be, right?

17
00:01:14,240 --> 00:01:16,010
This is referring to the class.

18
00:01:16,010 --> 00:01:19,400
So that's why we can just paste it in shape since it's ambiguous shape.

19
00:01:19,880 --> 00:01:20,450
This is fine.

20
00:01:20,520 --> 00:01:21,860
Well, we don't want to change anything.

21
00:01:21,860 --> 00:01:24,710
We literally just copy pasted it in the two other derived classes.

22
00:01:25,930 --> 00:01:34,720
So what have we to here, though, in the base class and I say, OK, well, this is a virtual function

23
00:01:34,720 --> 00:01:38,680
here, pure virtual function, and this is also a pure virtual function.

24
00:01:39,460 --> 00:01:48,280
Well, I know that I want this to be in forcibly implemented into triangles, circle and rectangle,

25
00:01:48,280 --> 00:01:51,010
all three of the drive classes, you know they should all have.

26
00:01:51,010 --> 00:01:52,030
This is bigger things.

27
00:01:52,030 --> 00:01:55,600
So what if I come here and I paste this?

28
00:01:55,600 --> 00:01:59,410
I get rid of the implementation because it's not going to have something for shape that this will never

29
00:01:59,410 --> 00:02:01,360
be instantiated, right?

30
00:02:03,230 --> 00:02:08,390
But what if I say, you know, this is going to be a pure virtual function, I go here and I leave the

31
00:02:08,390 --> 00:02:15,140
template and I save virtual and create a pure virtual function, both underline and read.

32
00:02:15,440 --> 00:02:16,700
Why is it doing that?

33
00:02:17,480 --> 00:02:21,800
Well, says virtual cannot be specified on member function templates.

34
00:02:23,760 --> 00:02:24,690
If I over here.

35
00:02:25,170 --> 00:02:28,260
Yeah, it's just a tied to this whole problem right here.

36
00:02:29,400 --> 00:02:31,140
So why can I not do that?

37
00:02:31,170 --> 00:02:39,750
Well, the problem is that you cannot declare a function, both virtual and also templated, and that

38
00:02:39,750 --> 00:02:47,940
is because when it's templated, what actually happens is that it resolves the fact that there could

39
00:02:47,940 --> 00:02:52,470
be different arguments at compile time and at compile time.

40
00:02:52,470 --> 00:02:56,660
Let's say, for example, I well, let's just use this example, right?

41
00:02:57,150 --> 00:03:05,490
I have like a potentially a triangle, a circle and a rectangle that can be passed to this right?

42
00:03:06,480 --> 00:03:12,690
So a compile time was C++ compiler is actually going to do is it's going to generate generate three

43
00:03:12,690 --> 00:03:16,890
different versions of this is bigger shape function.

44
00:03:16,890 --> 00:03:23,130
So like, for example, if I go in here, what's going to happen is it's going to make an is bigger

45
00:03:23,130 --> 00:03:27,900
shape or function where this would be a triangle.

46
00:03:28,200 --> 00:03:35,220
It's going to make another version of it where this would be a circle and it's going to make another

47
00:03:35,220 --> 00:03:37,620
version where this would be a rectangle.

48
00:03:38,580 --> 00:03:45,240
So basically, it does that based on the fact that we would have three calls to this right now.

49
00:03:45,450 --> 00:03:53,550
It might only consider the circle, but let's say that we have one of these calls for each one of the

50
00:03:53,550 --> 00:03:54,110
shapes.

51
00:03:54,120 --> 00:03:58,140
So, you know, like like, I would just take triangle, for example.

52
00:03:58,140 --> 00:03:59,720
So we had it in triangle, right?

53
00:03:59,730 --> 00:04:05,970
Let's say we go back to Maine and we actually had T. Arrow is bigger shape and we put a circle in here

54
00:04:05,970 --> 00:04:07,620
and then we a T. Arrow is bigger shape.

55
00:04:07,620 --> 00:04:15,690
And then we put that rectangle right with our star and then we put T is bigger shape with our T, which

56
00:04:15,690 --> 00:04:16,530
is another triangle.

57
00:04:17,160 --> 00:04:22,710
It would generate three different functions for this scene, the template it would know like, Oh,

58
00:04:22,710 --> 00:04:26,520
I need to make three different versions of this for each type that could be passed to it.

59
00:04:27,660 --> 00:04:31,620
So that's what happens with the templating of a member function.

60
00:04:32,010 --> 00:04:33,490
It happens at compile time.

61
00:04:33,510 --> 00:04:36,240
That's when I can reach those three things the virtual, though.

62
00:04:36,240 --> 00:04:38,190
So let's go back to where the problem was right here.

63
00:04:38,760 --> 00:04:43,410
Virtual is something that kind of resolves which function to call at runtime.

64
00:04:43,740 --> 00:04:48,060
You know, when you make these virtual functions, each one of our drive classes has a different version

65
00:04:48,060 --> 00:04:48,450
of it.

66
00:04:49,170 --> 00:04:57,150
That type of resolution is something to happen at runtime, and C++ cannot handle having these two different

67
00:04:57,150 --> 00:05:01,320
time periods of resolution on which thing to call.

68
00:05:02,070 --> 00:05:04,290
They have not created support for that yet.

69
00:05:04,560 --> 00:05:10,950
And it's just really difficult to make the compiler be able to handle such things.

70
00:05:12,240 --> 00:05:16,320
So that is why you might have already noticed that this is not possible.

71
00:05:16,590 --> 00:05:22,470
We cannot put a templated virtual spiritual function inside of the base class.

72
00:05:23,220 --> 00:05:24,840
Not a total problem, though.

73
00:05:24,850 --> 00:05:31,980
We can just delete this, all this and then each one will just have its own templated function and everything

74
00:05:31,980 --> 00:05:33,540
will work fine and dandy.

75
00:05:34,200 --> 00:05:41,730
So what we'd want to do at this point is go over to you may not see be and just kind of mix and match

76
00:05:42,270 --> 00:05:42,930
this stuff.

77
00:05:42,930 --> 00:05:43,380
So.

78
00:05:44,900 --> 00:05:48,110
Maybe I'll just go in here and copy paste this.

79
00:05:48,560 --> 00:05:57,410
So let's go right here and just say if maybe are as big a shape and then we'll put like tea in there

80
00:05:57,410 --> 00:06:03,440
and it will just say on duty type with tea area.

81
00:06:04,510 --> 00:06:07,690
Is bigger than the hour type.

82
00:06:09,690 --> 00:06:19,170
With our area, and we could do it first circle as well, so I mean pace this year, and I'll just say,

83
00:06:19,200 --> 00:06:19,800
see?

84
00:06:20,400 --> 00:06:27,960
And then on this one this past like hour and we'll just say that the.

85
00:06:29,830 --> 00:06:34,630
Our Typekit, our area is bigger than the sea type.

86
00:06:35,740 --> 00:06:40,000
With the area, so now we can kind of.

87
00:06:41,390 --> 00:06:47,470
Just refer to all of them, you know, and check on all of them where there's some other random shape,

88
00:06:47,480 --> 00:06:51,920
you know, random mass and three different choices passed to it would be a bigger area wise.

89
00:06:52,850 --> 00:06:54,500
So let's go ahead and run this.

90
00:06:56,780 --> 00:06:59,490
So let's see, we only get one right now.

91
00:06:59,510 --> 00:07:06,410
Was this the circle with this area is bigger than the triangle with this area, so we go ahead and have

92
00:07:06,410 --> 00:07:07,700
to change some things.

93
00:07:07,700 --> 00:07:11,690
Let's say what if we put like one hundred here?

94
00:07:14,880 --> 00:07:20,760
So now we have one that sets a rectangle with area one one two six one six is bigger than the circle

95
00:07:20,760 --> 00:07:23,490
with Area two seventy seven point two three seven.

96
00:07:26,040 --> 00:07:26,460
Cool.

97
00:07:26,520 --> 00:07:31,530
So you notice that are still working fine when we just implemented it in the derived classes, although

98
00:07:31,530 --> 00:07:38,040
we weren't quite able to put it in here as a spiritual function like we wanted to, but that's OK.

99
00:07:38,070 --> 00:07:43,140
We can just kind of resolve it by putting it in here and just leave it in the drive classes will still

100
00:07:43,140 --> 00:07:44,130
have access to it.

101
00:07:45,540 --> 00:07:46,050
OK.

102
00:07:46,170 --> 00:07:50,520
So with that, I'm going to in this video and the next video, I'll go for what I said I would talk

103
00:07:50,520 --> 00:07:55,320
about next, which is putting the templates on the classes as well.
