using const with function

what is the purpose of using const with function

  void readData () {}
  void readData const () {}
For that case, the const goes after the () and the function has to be a class member function. In the above, the const is before the () !

@Ivanka - is this a misprint as that is invalid syntax?
It is a promise that the function will not modify the object that it's called on.
obj.readData(); // will not modify obj 

It's similar to marking reference parameters as const.
void foo(const T&);
foo(obj); // will not modify obj 
Last edited on
Topic archived. No new replies allowed.