constメンバ関数でもmutableなメンバ変数なら修正できる

以下はmutableなメンバ変数をconstメンバ関数から修正する実験用コードです。

#include <iostream>
using namespace std;

class Hoge {
    mutable int hogeMutable;
public:
    int GetHogeMutable() const {
        return hogeMutable;
    }
    void SetHogeMutable(int hoge) const {
        // mutableなメンバ変数をconstメンバ関数から修正する
        hogeMutable = hoge;
    }
};

int main() {
    Hoge hoge;
    hoge.SetHogeMutable(100);
    cout << hoge.GetHogeMutable() << endl;

    return 0;
}

実行結果

100