Lecture overview -- Keyboard shortcut: 'u'  Previous page: Static class members -- Keyboard shortcut: 'p'  Next page: Const member functions - const and mutable -- 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 22 : 36
Notes about C++
Abstraction Mechanisms, Part 1
Const member functions

It is possible to mark a member function as constant

A constant member function is not allowed to change the state of the object.

In addition, it makes sense to call a constant member function on a constant object

  • The C++ Programming Language: Page 229
 

  • Effective C++, Third edition: Item 3
 

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


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


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