Lecture overview -- Keyboard shortcut: 'u'  Previous page: Const member functions -- Keyboard shortcut: 'p'  Next page: Object Self-reference -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 3 - Page 23 : 36
Notes about C++
Abstraction Mechanisms, Part 1
Const member functions - const and mutable

A member function may be logically constant, but the underlying state of the object may be physically non-constant (mutable)

It is possible to mark a data members as mutable

Mutable members can always be updated, even if they belong to a const object

  • The C++ Programming Language: Page 232
 

y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/const-members/situation-2/point.hA variant of Point with cached polar representation.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/const-members/situation-2/point.ccThe implementation of class Point - with compilation problems.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/const-members/situation-2/prog.ccA simple client program of Point.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/const-members/situation-2/program-outputProgram output.


The problem is that const member functions are not allowed to modify the caching variables.

In the next version - on the following page - we show how to deal with this problem