If you want the compiler to perform this action, declare a member function const:
bool contains(string word) const
{
...
}
A const - - const ( , -).
- - mutable. [ mutable const ; , "" const, ( ) - .]
, const , , .
, :
class Thingy
{
public:
void apple() const;
void banana();
};
class Blah
{
private:
Thingy t;
int *p;
mutable int a;
public:
Blah() { p = new int; *p = 5; }
~Blah() { delete p; }
void bar() const {}
void baz() {}
void foo() const
{
p = new int;
*p = 10;
baz();
bar();
t.banana();
t.apple();
a = 42;
}
};