Week 14 Day 3 - Inheritance
Channel:
Subscribers:
2,640
Published on ● Video Link: https://www.youtube.com/watch?v=MW9Sy1GiC98
Today we learned how to do inheritance in C++.
Suppose you have a class named Bob, and you want to make a new class named Cindy that gets everything in Bob copy-pasted into it by default. You do this:
class Cindy : public Bob {
};
Even with absolutely nothing in Cindy, everything in Bob magically appears in there. You can add new functions to the class, or you can change (override) old ones.
If you're going to be overriding a function in Bob, you should declare that function virtual, and you should declare the function in Cindy to be override:
class Bob {
virtual void whatever() { }
};
class Cindy : public Bob {
void whatever() override { }
};
Other Videos By Bill Kerney
2021-04-24 | Week 14 Day 3 - Inductive and Abductive Reasoning |
2021-04-23 | Week 15 Day 2 - Quake C Part IV |
2021-04-23 | Week 15 Day 2 - Linker Errors, The Bus |
2021-04-22 | Week 14 Day 2 |
2021-04-21 | Week 15 Day 2 - Advanced Topics, Histogramming |
2021-04-21 | Week 15 Day 1 - QuakeC Part III - Traceline, Hitscan Weapons, and Find |
2021-04-21 | Week 15 Day 1 - Shell Scripting, Github |
2021-04-20 | Week 14 Day 1 - Set Theory |
2021-04-19 | Week 15 Day 1 - Multiple Inheritance, Virtual Inheritance, and Smart Pointers |
2021-04-18 | Week 14 - Projecting from World Space to View Space |
2021-04-17 | Week 14 Day 3 - Inheritance |
2021-04-16 | Week 12 Day 3 - Midterm Review |
2021-04-16 | Irish Trad Music Workshop |
2021-04-15 | Week 14 Day 2 - Quake Modding III |
2021-04-15 | Week 14 Day 2 - UNIX Utilities |
2021-04-15 | Week 12 Day 2 - Midterm Review |
2021-04-14 | Week 14 Day 2 - Bitfields |
2021-04-14 | Week 14 Day 1 - Quake Modding |
2021-04-14 | Week 14 Day 1 - Static vs Dynamic Linking |
2021-04-13 | Week 14 Day 1 - Hash Tables and Heaps |
2021-04-13 | Week 12 Day 1 - Cryptography |
Tags:
csci 41
c++
inheritance
virtual
override