What is the static_cast runtime overhead if adding constness while keeping the same type?

两盒软妹~` 提交于 2019-12-02 05:58:58

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!