ποΈ
STUDENT NOTES Β· C & C++ WEEK 7 OF 8
Family Trees & the Toolbox ποΈ
Classes that inherit from classes β and the STL: C++'s legendary box of ready-made tools.
1Inheritance β Batman IS a Hero
βοΈ
Chip: class Batman : public Hero β Batman gets everything Hero has, plus his own gadgets. Write the common stuff once, inherit it everywhere.
2virtual β each object answers as itself
π¦
Professor Hoot: Through a Hero pointer, a virtual function calls the RIGHT override: Batman broods, Thor thunders. That's runtime polymorphism β the crown jewel of OOP.
3vector β the array that finally grows
π€
Bittu: push_back = Python's append. size() = len. C arrays with seatbelts AND stretch. Where were vectors in Week 3, you ask? Being earned.
4map & sort β dictionary and order, C++ style
5Quick quiz! π§
class Batman : public Hero meansβ¦
π‘ Inheritance: the child class receives the parent's members and adds its own.
What makes vector better than a C array for growing data?
π‘ Vectors grow on demand and know their size β the Week 3 pain, solved by the STL.
6Your mission π
Mission 1: Build Animal β Dog/Cat with a virtual speak(). Make a Hero pointer zoo speak.
Mission 2: Read 5 marks into a vector with push_back, print the size and the max.
Mission 3: Build map<string,int> shirt numbers for 3 players, print Messi's.
Week 7 complete β the toolbox is yours! ποΈ
Final week: multithreading β and shipping your project.
Go to Week 8: The Final Boss β