Week 14 Day 3 - Inheritance

Channel:
Subscribers:
2,640
Published on ● Video Link: https://www.youtube.com/watch?v=MW9Sy1GiC98



Duration: 1:37:38
99 views
1


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 { }

};







Tags:
csci 41
c++
inheritance
virtual
override