"C + + Primer The seventh chapter" "C + + Primer Seventh" Defines the data abstraction class

Source: Internet
Author: User

Screen class

• We can explain inline at the same time as it is declared and defined, but it is actually legal. However, it is best to explain inline only where it is defined outside the class.

Variable data members

variable data members : sometimes (but not often) it happens that we want to be able to modify a data member of a class, that is, within a const member function, and you can do this by adding the mutable keyword to the declaration of the variable.

• A mutable data member is never a const, even if it is a member of a const object.

1 class Screen2 {3  Public:4     voidSome_member ()Const;5 6 Private:7mutable size_t access_ctr;//even in a const object can be modified8 };9 Ten voidScreen::screen ()Const One { A++access_ctr;//saves a count value that records the number of times a member function is called -     //other work that the member needs to complete -}

"C + + Primer The seventh chapter" "C + + Primer Seventh" Defines the data abstraction class

Related Article

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.