I find it irritating that I can call non-const functions of an object if I have a pointer to this object. I cannot let the pointer be a const pointer because there are also non-
The runtime overhead is essentially a pointer copy, which may be optimised out altogether.
But in your case, I'd consider changing int m_i;
to mutable std::atomic<int> m_i;
and make increment
constant in the base class too. It looks like a reference counter and my way allows you to (i) retain const
-correctness and (ii) be thread safe. I'd also consider changing int
to unsigned
to avoid undefined behaviour if m_i
gets too big.