Simple and fun C ++ keywords mutable

Source: Internet
Author: User

Mutable is a fun C ++ keyword and it was my first time. So I checked msdn and found that it was a fun keyword.
First, it can only modify non-const, non-static class data members.
Second, it is used to break through the const function.
Again, it is such a function.

Class X {public: // logically, getflag only obtains my m_flag status, so it is modified to const //. However, I need to know some of the dynamic statuses, so Mutable was born. Bool getflag () const {m_accesscount ++; return m_flag;} PRIVATE: bool m_flag; // The rules of this keyword are non-const and non-staticmutable int m_accesscount ;};

Conclusion: The idea is simple, the design is simple, and the function is simple.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.