A. const で呼び出した class の member function で使う “read-only” な function です.
もっと詳しく言うと,
- constant function の中では メンバ変数を変更できない(コンパイルエラーになる).
- const class の メンバクラス も const class として扱われる.
- ROS2 では callback function が constatnt function になっている.おそらく,
std::make_shared
でstd::shared_ptr
を作るときに class が const として扱われている. - const function ないでメンバクラスのメソッドを呼び出す場合は,そのメソッドも constant function じゃないとコンパイルエラーになる.
参考:
13.12 — Const class objects and member functions – Learn C++

const (C++)
Learn more about: const (C++)
コメント