Lecture 12
Recall const obj, const methods
Now consider: We want to collect usage stats on student objects
If you remove const from grade(), then you cannot call grade on const Students, but mutating numMethodCalls affects only the physical constness of student objects, not logical constness.
We want to be able to update numMethodCalls even if the object is const. ANSWER: Declare field mutable
Static Fields and Methods
numMethodCalls tracked number of times method was called on for particular object.
What if we want to track the number of times a method is called over all student objs? Or what if we want to track how many students are created? ANSWER: Static members!
Last updated