ITP 165x Lecture Notes - Lecture 14: Member Variable

40 views1 pages

Document Summary

Itp 165: intro to c++ - lecture 14: classes. Member functions that can operate on the member variables. And we have the option to prevent other code from directly modifying member variables. If something is private, that means it cannot be directly accessed from outside the class. So by adding the private: before the variables, we are explicitly saying that everything following this is private. If something is public, that means it can be directly accessed. If you don"t specify public or private, it will default to private. Unless you have a good reason, all member variables (aka properties) should be private. Following this rule in a class is also called data encapsulation. Example of clock class: class clock { private: int mhours; int mminutes; int mseconds; public: void sethours(int newhours) { if (newhours >= 0 && newhours <= 23) Getter function - a member function that returns a member variable.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents