Computer Science 1037A/B Lecture Notes - Lecture 24: Member Variable

18 views4 pages

Document Summary

One instance of variable for the entire class. Can be used to access static member variables. Can be called before any class objects are created. Must be declared in class with keyword static. Can be accessed or modified by any object of the class. Modifications by one object are visible to all objects of the class. Budget() { divbudget = 0; } void addbudget(double b) divbudget += b; corpbudget += divbudget; double getdivbudget() { return divbudget; } double getcorpbudget() { return corpbudget; } This program demonstrates a static class member variable. #include "budget. h" //for budget class declaration using namespace std; //definition of the static member of the budget class double budget::corpbudget = 0; Classes and objects 2 page 2 double budget::corpbudget = 0; int main() const int n_divisions = 4; Can be called independently of class objects, through the class name: Because of item 2 above, the this pointer cannot be used.

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

Related Questions