// f() const - this function/method cannot change any of the object members in which it is called.
// It's a non-mutable member function
#include <iostream>
class Example {
private:
int num = 34;
public:
Example() {};
void change() {
num = 17;
}
void cannotchange() const {
// num = 100; // error: assignment of member 'Example::num' in read-only object
}
void print() {
std::cout << num << "\n";
}
};
int main() {
Example obj;
obj.change();
obj.print();
}
/*
run:
17
*/