ITP 165x Lecture Notes - Lecture 22: Snickers, Member Variable
Document Summary
Itp 165: intro to c++ - week 13, lecture 21: inheritance and polymorphism. Anything inheriting is a child - a type of base class that is being inherited from. Parent class should have public functions and variables so child classes can have access. The private member variables are only available to class functions, not children"s functions. The protected keyword - like public and private - it changes accessibility for parts of class. Grants access to the class and all its children. They can have extra variable and functions unique to that class, but also have the parent variables/functions. Class chocolate : public candy - defines chocolate as a child of candy. When making a child constructor, c++ first makes a parent class. To make c++ use a different constructor, we"ll need to use an initialization list. Chocolate::chocolate(std::string inname, double incals, double inperc) : Uses constructor from parent and also initializes regular member variable.