1 00:00:05,550 --> 00:00:09,210 One of the most powerful features of inheritance is that base 2 00:00:09,210 --> 00:00:12,379 class member functions are available to the derived class. 3 00:00:13,469 --> 00:00:16,619 A derived class can directly invoke base class methods. 4 00:00:17,260 --> 00:00:21,310 A derived class can also override or redefine base class methods. 5 00:00:22,070 --> 00:00:24,430 This concept will provide us with a large amount of 6 00:00:24,430 --> 00:00:27,740 power when we use polymorphic functions in the next section. 7 00:00:28,500 --> 00:00:31,970 In order to redefine or override a method, you simply provide 8 00:00:31,970 --> 00:00:35,499 a method in the derived class with the same name and signature 9 00:00:35,670 --> 00:00:37,230 as a method in the base class. 10 00:00:37,580 --> 00:00:38,800 Let's see an example. 11 00:00:38,880 --> 00:00:42,190 Here we'll both use and override a base class method. 12 00:00:45,150 --> 00:00:49,000 Suppose we have an account class and it has a deposit method that simply 13 00:00:49,000 --> 00:00:50,650 increments a balance by an amount. 14 00:00:51,670 --> 00:00:55,150 Now we have a savings account class, and it also needs a deposit 15 00:00:55,150 --> 00:00:58,320 method, but its behavior will be slightly different in some way. 16 00:00:59,010 --> 00:01:02,050 We can override the account classes deposit method in the 17 00:01:02,050 --> 00:01:06,089 savings account class by providing a specialized implementation 18 00:01:06,259 --> 00:01:07,949 using the same method signature. 19 00:01:09,009 --> 00:01:12,379 Now when the savings account objects deposit funds, this 20 00:01:12,389 --> 00:01:13,670 specialized method will be invoked. 21 00:01:14,980 --> 00:01:18,610 But since the accounts deposit method does some of the work that we want 22 00:01:18,610 --> 00:01:22,270 to do in the savings account deposit method, we don't have to duplicate 23 00:01:22,270 --> 00:01:27,265 code, we can simply call the accounts deposit method from within the 24 00:01:27,289 --> 00:01:28,612 savings accounts deposit method. 25 00:01:29,029 --> 00:01:30,929 You can see the syntax makes sense. 26 00:01:31,160 --> 00:01:35,360 We must prefix the method call with the account class so the compiler 27 00:01:35,360 --> 00:01:38,360 knows that we're calling the deposit method in the account class. 28 00:01:38,950 --> 00:01:42,080 It's super important that we don't try to do the actual deposit 29 00:01:42,259 --> 00:01:43,800 in the savings account method. 30 00:01:44,240 --> 00:01:47,549 Instead, let the account class do what it knows how to do. 31 00:01:48,000 --> 00:01:51,570 If the base functionality for deposit ever changes, it won't 32 00:01:51,570 --> 00:01:55,090 affect our savings account deposit method since all it's doing is 33 00:01:55,090 --> 00:01:56,949 delegating this to the account class. 34 00:02:00,639 --> 00:02:03,350 Let's finish up this video by talking about static binding. 35 00:02:04,080 --> 00:02:07,590 By default, c++ does static binding of method calls. 36 00:02:08,050 --> 00:02:11,560 All that means is that the compiler determines which methods are called 37 00:02:11,900 --> 00:02:13,910 based on what it sees at compile time. 38 00:02:14,780 --> 00:02:18,280 Static binding is super efficient and that's why it's the default in c++. 39 00:02:19,690 --> 00:02:24,399 So if the compiler sees that a b is declared as a base object and we 40 00:02:24,400 --> 00:02:28,910 call b.deposit, then the compiler will call the base classes deposit. 41 00:02:29,940 --> 00:02:31,859 The same is true for a derived object. 42 00:02:32,520 --> 00:02:37,340 If d is a derived object and d.deposit is called, this results in a call to 43 00:02:37,340 --> 00:02:39,540 the derived classes deposit method. 44 00:02:40,279 --> 00:02:43,450 While this is very efficient and fine in most cases, there 45 00:02:43,459 --> 00:02:46,090 are times when we'd like the binding to take place at runtime. 46 00:02:47,110 --> 00:02:48,500 We'll see that in the next section. 47 00:02:48,780 --> 00:02:50,440 Let's see a couple of examples next. 48 00:02:52,520 --> 00:02:56,739 In the first example here, you can see that b.deposit will call 49 00:02:56,740 --> 00:03:01,230 the base classes deposit method because b is a base object. 50 00:03:01,950 --> 00:03:06,660 And d.deposit we'll call the derived classes deposit method 51 00:03:06,660 --> 00:03:09,069 since d is a type of derived. 52 00:03:09,840 --> 00:03:11,740 But consider the last two lines of code. 53 00:03:12,320 --> 00:03:16,999 In this case, we have a pointer ptr to a base object, but we 54 00:03:17,000 --> 00:03:20,270 create a derived object on the heap and assign it to the pointer. 55 00:03:21,130 --> 00:03:24,300 This is perfectly valid since the derived is a base. 56 00:03:24,710 --> 00:03:27,650 But now if we call the deposit method through the pointer, the 57 00:03:27,650 --> 00:03:31,770 compiler will call the base classes deposit method because it sees that 58 00:03:31,780 --> 00:03:33,900 pointer is a pointer to a base class. 59 00:03:35,070 --> 00:03:38,400 But perhaps it would make more sense to call the derives deposit method 60 00:03:38,400 --> 00:03:43,350 in this example since the actual object pointed to is a derived object. 61 00:03:44,030 --> 00:03:47,320 As I said, we'll learn how to achieve this kind of dynamic binding in 62 00:03:47,320 --> 00:03:50,200 the next section, but it's very important to understand that by 63 00:03:50,200 --> 00:03:52,960 default c++ uses static binding. 64 00:03:54,770 --> 00:03:55,850 Okay, so I'm in the IDE. 65 00:03:56,120 --> 00:04:01,200 I'm in the section 15 workspace in the RedefiningBaseClassMethods project. 66 00:04:01,750 --> 00:04:05,230 And what we've got here is a real simple account class, and we'll derive 67 00:04:05,230 --> 00:04:08,470 a savings account class from it, similar to what we did in the slides, 68 00:04:08,790 --> 00:04:12,060 and we'll do it from scratch that way you can see how this works with using 69 00:04:12,389 --> 00:04:14,810 and redefining base class methods. 70 00:04:15,000 --> 00:04:16,750 So let's take a look at the account class. 71 00:04:17,089 --> 00:04:20,668 We've got a friend here that allows us just to put account objects on a 72 00:04:20,670 --> 00:04:22,379 stream and display them really easily. 73 00:04:23,110 --> 00:04:25,399 And what we're modeling is the balance, right. 74 00:04:25,509 --> 00:04:26,799 That's the whole idea of an account. 75 00:04:26,839 --> 00:04:29,139 It models a balance, and it's a double in this case. 76 00:04:29,139 --> 00:04:31,149 And then we've got some public methods here. 77 00:04:31,150 --> 00:04:33,770 With no args constructor, we've got a constructor 78 00:04:33,770 --> 00:04:35,940 right here that's overloaded where you supply the balance. 79 00:04:36,530 --> 00:04:38,469 And then we've got a deposit and a withdrawal method. 80 00:04:38,490 --> 00:04:42,420 Now the deposit and withdraw functionality is dead simple, right. 81 00:04:42,420 --> 00:04:43,810 Give me an amount, I'll deposit it. 82 00:04:44,070 --> 00:04:45,570 Give me an amount, I'll withdraw it. 83 00:04:45,690 --> 00:04:48,289 The only thing we're checking is to make sure that there's enough balance 84 00:04:48,289 --> 00:04:50,030 so that we can withdraw the funds. 85 00:04:50,490 --> 00:04:51,830 Okay, so that's it. 86 00:04:51,840 --> 00:04:53,400 Let's take a look at the implementation. 87 00:04:53,620 --> 00:04:55,770 Now you'll notice that there are no copy constructors, 88 00:04:55,800 --> 00:04:58,690 move constructors, overloaded assignment operators and so forth. 89 00:04:58,910 --> 00:04:59,669 We don't need them. 90 00:04:59,920 --> 00:05:02,420 We're modeling a double, and it really doesn't make 91 00:05:02,420 --> 00:05:03,540 any sense to include them. 92 00:05:03,849 --> 00:05:06,880 The compiler provided ones are perfectly adequate. 93 00:05:07,200 --> 00:05:09,340 So let's take a look at the source. 94 00:05:10,750 --> 00:05:13,030 And again, you can see real, real simple stuff here. 95 00:05:13,270 --> 00:05:16,689 What I've got is my no args constructor right here. 96 00:05:17,240 --> 00:05:21,449 And when that is invoked, then all I'm doing is I'm calling my 97 00:05:21,780 --> 00:05:24,763 regular overloaded constructor right here, and I'm passing in a 98 00:05:24,800 --> 00:05:27,040 0 to it so I'm delegating to it. 99 00:05:27,500 --> 00:05:31,260 And at this point, that constructor just simply sets the balance to 100 00:05:31,260 --> 00:05:32,909 balance, right, simple as that. 101 00:05:33,419 --> 00:05:36,509 The deposit method increments the balance by whatever 102 00:05:36,509 --> 00:05:37,899 amount was passed in. 103 00:05:38,870 --> 00:05:40,980 The withdraw method expects an amount. 104 00:05:41,260 --> 00:05:43,169 We want to make sure that there are sufficient funds. 105 00:05:43,170 --> 00:05:45,810 If there are, we're just going to subtract the amount from the balance. 106 00:05:46,050 --> 00:05:48,979 Otherwise, we'll just display a simple message insufficient funds. 107 00:05:49,290 --> 00:05:52,400 And here's my overloaded insertion operator. 108 00:05:53,639 --> 00:05:54,900 Okay, so there you go. 109 00:05:55,020 --> 00:05:55,960 Simple stuff. 110 00:05:56,340 --> 00:06:00,489 Now what we'll do is let's take a look at our savings account. 111 00:06:01,330 --> 00:06:04,430 Okay, so here's the savings account class header file. 112 00:06:04,660 --> 00:06:06,289 We're including account header file. 113 00:06:06,690 --> 00:06:09,389 And a savings account is an account. 114 00:06:09,440 --> 00:06:10,979 So you can see the inheritance right here. 115 00:06:10,980 --> 00:06:12,870 Class savings account, public account. 116 00:06:13,099 --> 00:06:14,980 We're using "is a" inheritance here. 117 00:06:15,410 --> 00:06:19,550 And a savings account is an account, so it's going to provide a balance 118 00:06:19,560 --> 00:06:22,710 just like the account, but what it does add is an interest rate. 119 00:06:23,270 --> 00:06:27,309 So the interest rate is used when users deposit funds. 120 00:06:27,570 --> 00:06:31,280 So if you deposit a 1000 dollars and we've got a 5% interest rate, 121 00:06:31,570 --> 00:06:34,930 the amount that you deposit will be one 1000 plus 50 dollars. 122 00:06:35,070 --> 00:06:37,970 So we're giving folks really good bonuses here, I wish 123 00:06:37,990 --> 00:06:39,060 my bank account did this. 124 00:06:39,230 --> 00:06:41,289 So anyway, so that's what we're going to do. 125 00:06:41,710 --> 00:06:44,000 Now the withdraw method doesn't specialize 126 00:06:44,340 --> 00:06:46,859 so the idea there is that we can use our parents or our 127 00:06:46,860 --> 00:06:49,160 accounts withdraw method as is. 128 00:06:49,309 --> 00:06:50,549 We don't have to do anything. 129 00:06:50,820 --> 00:06:52,509 We don't have to declare it in here because we'll 130 00:06:52,539 --> 00:06:53,880 automatically inherit it. 131 00:06:54,469 --> 00:06:57,320 All right, so why don't we start doing this class right here. 132 00:06:57,660 --> 00:07:00,070 So let's start writing the code for this class right here. 133 00:07:00,310 --> 00:07:02,670 First thing we want to do is we want to declare that friend of ours 134 00:07:02,700 --> 00:07:03,899 minus well get it out of the way. 135 00:07:04,410 --> 00:07:09,020 And it's going to return a std output stream reference, its 136 00:07:09,450 --> 00:07:12,389 operator and the insertion operator. 137 00:07:13,340 --> 00:07:14,320 And what does expect? 138 00:07:14,320 --> 00:07:20,670 Well, it expects a std ostream by reference and I'll just call that os. 139 00:07:21,280 --> 00:07:24,929 This design pattern here you'll see over and over used in c++. 140 00:07:25,870 --> 00:07:30,330 And in this case, it expects a savings account object, right. 141 00:07:30,330 --> 00:07:32,090 And we'll call it account by reference. 142 00:07:34,250 --> 00:07:35,790 So that's the prototype for that. 143 00:07:35,790 --> 00:07:38,349 We'll implement that in the c++ file later. 144 00:07:38,710 --> 00:07:39,860 Hopefully, I don't have any typos. 145 00:07:39,860 --> 00:07:41,940 I'll deal with typos after when we compile that way. 146 00:07:41,940 --> 00:07:43,299 We don't waste a lot of time now. 147 00:07:44,190 --> 00:07:45,000 That's it. 148 00:07:45,080 --> 00:07:46,060 So now what do we want to do? 149 00:07:46,080 --> 00:07:47,820 Well, we have to add what we add, right. 150 00:07:47,820 --> 00:07:49,340 We're adding an interest rate. 151 00:07:49,340 --> 00:07:52,490 So we'll use a protected keyword here. 152 00:07:53,100 --> 00:07:55,530 And we'll supply our interest rate, which will be a double, 153 00:07:55,530 --> 00:07:56,810 and I'll just call it int rate. 154 00:07:58,820 --> 00:07:59,820 Okay, that's it. 155 00:08:00,059 --> 00:08:02,880 And now what we'll do is we'll provide some public methods, 156 00:08:02,880 --> 00:08:04,599 in this case, our constructors. 157 00:08:04,859 --> 00:08:08,440 So it'll be a savings account constructor, that'll 158 00:08:08,450 --> 00:08:10,200 be a no args constructor. 159 00:08:10,200 --> 00:08:13,480 We'll also supply a savings account constructor. 160 00:08:13,520 --> 00:08:19,769 In this case, that will expect the balance, which will be handled by the 161 00:08:19,770 --> 00:08:23,750 account part of me and the interest rate which will be handled by me, 162 00:08:24,410 --> 00:08:26,650 me being the savings account class. 163 00:08:27,790 --> 00:08:30,510 And we also have to handle the deposit method because we're 164 00:08:30,510 --> 00:08:32,070 redefining it overriding it. 165 00:08:32,289 --> 00:08:35,710 So in this case, we want the same function prototype 166 00:08:35,710 --> 00:08:36,679 as we had in our parent. 167 00:08:36,990 --> 00:08:39,999 So it's deposit, and I believe it was double amount. 168 00:08:41,820 --> 00:08:42,280 That's it. 169 00:08:42,650 --> 00:08:46,090 Notice withdraw is inherited. 170 00:08:47,760 --> 00:08:51,960 Okay, and the functionality that we're using to withdraw funds in 171 00:08:51,960 --> 00:08:55,120 the account class is all I need in the savings account class. 172 00:08:56,110 --> 00:08:57,669 All right, so now let's implement this. 173 00:08:58,080 --> 00:09:00,059 There's only a few methods to implement so it should be pretty 174 00:09:00,059 --> 00:09:01,610 quick and pretty straightforward. 175 00:09:01,700 --> 00:09:04,230 Here you go. I'm including my savings account header file. 176 00:09:04,620 --> 00:09:07,600 And let's do the no args constructor. 177 00:09:07,600 --> 00:09:10,759 Actually, let's do the second constructor first, the savings 178 00:09:10,760 --> 00:09:18,720 account, the overloaded constructor and it's this guy right here and 179 00:09:18,720 --> 00:09:26,050 expects a double for balance and another double for the interest rate. 180 00:09:28,380 --> 00:09:29,629 Let's fix that typo here. 181 00:09:30,020 --> 00:09:32,749 So those are the two parameters in this particular constructor. 182 00:09:32,759 --> 00:09:33,880 Now what do we want to do here? 183 00:09:34,309 --> 00:09:37,270 Well, we want to initialize the account part of us, right. 184 00:09:37,600 --> 00:09:40,970 So we want to invoke our account part constructor, 185 00:09:40,970 --> 00:09:42,050 right, our parents constructor. 186 00:09:42,050 --> 00:09:43,959 And that expects just the balance. 187 00:09:43,960 --> 00:09:44,930 That's all it knows about. 188 00:09:44,930 --> 00:09:46,619 It doesn't know anything about the interest rate. 189 00:09:47,070 --> 00:09:52,199 And then once that's initialized, I can come back and take care of the 190 00:09:52,199 --> 00:09:55,689 interest rate and initialize that. 191 00:09:56,370 --> 00:09:58,610 There is no body to this constructor. 192 00:09:58,610 --> 00:09:59,470 You can just leave it like that. 193 00:09:59,470 --> 00:10:02,829 If you want to type something like cout constructor called, that's fine. 194 00:10:03,139 --> 00:10:05,390 But we really don't need to do anything else here. 195 00:10:05,630 --> 00:10:11,920 Okay, so now how about the no args constructor? 196 00:10:11,920 --> 00:10:14,420 Well, let's do that one. 197 00:10:14,420 --> 00:10:15,699 That one's pretty easy to do, right. 198 00:10:16,180 --> 00:10:18,010 So here's my no args constructor. 199 00:10:18,010 --> 00:10:20,280 It expects nothing. 200 00:10:20,610 --> 00:10:21,759 Now what do we want to do here? 201 00:10:21,760 --> 00:10:25,029 Well, the simplest thing to do is just to delegate to my 202 00:10:25,030 --> 00:10:26,320 overloaded constructor, right. 203 00:10:26,559 --> 00:10:29,820 So what I want to do here is delegate to my savings account 204 00:10:29,830 --> 00:10:31,350 overloaded constructor up here. 205 00:10:31,710 --> 00:10:35,990 And what I want to pass into it is 0.0 for the balance, 206 00:10:36,560 --> 00:10:38,910 and 0.0 for the interest rate. 207 00:10:40,889 --> 00:10:41,560 And that's it. 208 00:10:41,570 --> 00:10:42,420 That'll take care of that. 209 00:10:42,420 --> 00:10:43,850 So my two constructors are done. 210 00:10:44,150 --> 00:10:47,380 We don't have any destructors or copy constructors or anything like that. 211 00:10:47,730 --> 00:10:50,500 So let's worry about the deposit method, right. 212 00:10:50,630 --> 00:10:56,720 So let's say void and its savings account, it's my deposit 213 00:10:56,720 --> 00:11:01,110 method, and it expects a double, which is the amount to deposit. 214 00:11:02,679 --> 00:11:05,209 What we want to do here is we want to increment that amount by 215 00:11:05,209 --> 00:11:06,709 that interest rate, as I said. 216 00:11:06,710 --> 00:11:08,900 So what we want to do is we want to figure out how 217 00:11:08,900 --> 00:11:10,100 much do we need to deposit. 218 00:11:10,110 --> 00:11:11,280 So let's say amount. 219 00:11:11,820 --> 00:11:13,270 That's, that same amount right here. 220 00:11:13,980 --> 00:11:16,650 We could use another variable name if we want but this works just fine. 221 00:11:16,870 --> 00:11:23,420 A local variable, I mean amount equals amount plus and we'll say 222 00:11:23,420 --> 00:11:29,320 amount times the interest rate divided by a 100, that'll give us the 223 00:11:29,320 --> 00:11:32,100 percentage, and that should do it. 224 00:11:33,570 --> 00:11:36,130 We could have set amount plus equals as well to be a little clearer. 225 00:11:36,320 --> 00:11:37,979 Now we know how much we need to deposit. 226 00:11:38,230 --> 00:11:41,990 So rather than do it ourselves, let's just let the account 227 00:11:42,160 --> 00:11:43,569 parent part of us do it. 228 00:11:43,850 --> 00:11:49,150 So we'll say account, it's got a deposit method in there, and 229 00:11:49,150 --> 00:11:52,150 we'll pass in the amount that we wanted to deposit for us. 230 00:11:53,660 --> 00:11:54,230 That's it. 231 00:11:54,580 --> 00:11:58,319 And then finally, we'll implement the friend overloaded operator. 232 00:11:59,180 --> 00:12:02,610 So this returns a ref to an ostream, and we're overloading 233 00:12:02,610 --> 00:12:04,530 operator, our insertion operator. 234 00:12:04,940 --> 00:12:09,589 Again, std ostream by reference and we'll call it os. 235 00:12:10,400 --> 00:12:15,209 And we've got a const savings account ref. 236 00:12:16,949 --> 00:12:21,410 Okay, and all we're doing here is we're saying -- we're 237 00:12:21,440 --> 00:12:23,950 putting onto that output stream, we'll say something 238 00:12:23,970 --> 00:12:26,709 like savings account balance. 239 00:12:29,800 --> 00:12:39,460 And we'll put the accounts balance on here followed by the interest rate 240 00:12:42,360 --> 00:12:44,569 and the interest rate for the account. 241 00:12:45,330 --> 00:12:47,939 And we know it's got it because it is a savings account right here. 242 00:12:50,750 --> 00:12:53,480 That should do it, and we want to return that ostream. 243 00:12:55,180 --> 00:12:58,050 All right, so let's compile this and see if we've got 244 00:12:58,050 --> 00:12:59,560 any typos, we probably do. 245 00:13:00,370 --> 00:13:04,470 And there's one right here. 246 00:13:08,099 --> 00:13:09,499 Okay, cool, so we have a run. 247 00:13:09,799 --> 00:13:11,160 Let me show you the main real quick. 248 00:13:13,000 --> 00:13:15,650 And you'll notice one thing right away, it wasn't a lot 249 00:13:15,650 --> 00:13:16,680 of work to do this, right. 250 00:13:16,700 --> 00:13:18,620 That's the whole point of reusing. 251 00:13:19,080 --> 00:13:22,120 All I had to do is create these constructors, right, 252 00:13:22,150 --> 00:13:23,850 override that deposit method. 253 00:13:24,290 --> 00:13:25,840 The rest is just came right in. 254 00:13:25,849 --> 00:13:27,790 The withdraw method I didn't have to touch because I'm 255 00:13:27,790 --> 00:13:28,989 inheriting it from my parent. 256 00:13:29,320 --> 00:13:31,880 So let's take a look at the main real quick, and I just wrote a couple 257 00:13:31,880 --> 00:13:35,750 simple test cases here where I'm creating an account a1 with a 1000 258 00:13:35,760 --> 00:13:37,460 dollars in it, and I'm displaying it. 259 00:13:37,940 --> 00:13:41,119 And I'm depositing 500 into it, I'm withdrawing a 1000 and then 260 00:13:41,570 --> 00:13:44,319 I'm withdrawing 5000 and I'm going to get insufficient funds. 261 00:13:44,599 --> 00:13:46,330 So let's build and run that. 262 00:13:46,340 --> 00:13:52,319 And you can see here, we've got a 1000, 1500, 500 insufficient 263 00:13:52,320 --> 00:13:54,250 funds, and we still have 500. 264 00:13:55,320 --> 00:13:58,930 Okay, and then we've got some test cases down here that 265 00:13:58,930 --> 00:14:01,970 work with these actual savings accounts that we just created. 266 00:14:02,330 --> 00:14:03,520 So let's run those. 267 00:14:04,660 --> 00:14:10,950 And you could see here now that I've got a savings account with a balance 268 00:14:10,950 --> 00:14:12,969 of a 1000 and an interest rate of 5. 269 00:14:13,630 --> 00:14:17,600 I've got -- after the deposit, notice that 1000 was deposited, 270 00:14:17,600 --> 00:14:22,120 but 1050 was deposited because that was our specialized deposit method. 271 00:14:22,480 --> 00:14:25,480 So now we've got a balance of 2050, same interest rate. 272 00:14:26,130 --> 00:14:28,510 I'm going to withdraw 2000, which leaves us with 273 00:14:28,510 --> 00:14:30,089 a 50 balance right here. 274 00:14:30,610 --> 00:14:33,530 Then if I try to withdraw a 1000, obviously, I've got insufficient 275 00:14:33,530 --> 00:14:36,200 funds, and then I display it again and we still have 50. 276 00:14:37,630 --> 00:14:38,480 Okay, so there you go. 277 00:14:38,480 --> 00:14:41,709 That's an example of reusing an account class. 278 00:14:42,029 --> 00:14:45,460 And we're using the withdraw method, 100% right. 279 00:14:45,820 --> 00:14:50,240 And if you look again at the deposit method, we really are reusing it, 280 00:14:50,250 --> 00:14:51,680 we're actually calling it right here. 281 00:14:52,179 --> 00:14:54,920 And all we're doing is tweaking the amount that we want deposited 282 00:14:54,920 --> 00:14:56,340 and then just sending it right up. 283 00:14:56,679 --> 00:15:00,490 Now one thing I should mention, we overloaded the insertion 284 00:15:00,490 --> 00:15:03,400 operator here to work with the savings account simply to 285 00:15:03,400 --> 00:15:05,670 display the interest rate, right. 286 00:15:06,010 --> 00:15:11,559 If you send in a savings account object to this guy right here in 287 00:15:11,559 --> 00:15:15,260 the account class, remember, a savings account is an account. 288 00:15:15,710 --> 00:15:18,730 What will happen here is the object will get sliced and it will only print 289 00:15:18,780 --> 00:15:22,260 out the account balance, not the interest rate because the compiler 290 00:15:22,260 --> 00:15:23,560 is going to slice that part out. 291 00:15:23,750 --> 00:15:27,170 So the only reason that we're implementing this guy right here on 292 00:15:27,170 --> 00:15:31,130 line 18 in the savings account cpp is so that we can see the interest rate. 293 00:15:32,190 --> 00:15:34,560 So what we'll do in the next video is I'll give you the beginnings 294 00:15:34,590 --> 00:15:36,810 of an account class hierarchy. 295 00:15:37,130 --> 00:15:40,440 And in the challenge, what you'll do is add some more accounts to 296 00:15:40,440 --> 00:15:43,830 this that have more specialized behavior so you can get some 297 00:15:43,830 --> 00:15:45,350 experience with inheritance. 298 00:15:45,370 --> 00:15:48,250 And remember, all of this is using static binding, 299 00:15:48,570 --> 00:15:49,740 which is real important.