volatile vs. mutable in C++

前端 未结 6 1923
旧时难觅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 06:13

    A variable marked mutable allows for it to be modified in a method declared const.

    A variable marked volatile tells the compiler that it must read/write the variable every time your code tells it too (i.e. it cant optimize away accesses to the variable).

提交回复
热议问题