ITP 165x Lecture Notes - Lecture 22: Snickers, Member Variable

53 views2 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents