volatile vs. mutable in C++

前端 未结 6 1920
旧时难觅i
旧时难觅i 2020-12-04 05:26

I have a question about the difference between volatile and mutable. I noticed that both of the two means that it could be changed. What else? Are they the same thing? What\

6条回答
  •  青春惊慌失措
    2020-12-04 05:58

    A crude but effective way of thinking of the difference is:

    • The compiler knows when a mutable object changes.
    • The compiler cannot know when a volatile object changes.

提交回复
热议问题