Deep understanding of common keyword meanings in C + + _c language

Source: Internet
Author: User
Tags function definition
1. Inline: defines an inline function, which is based on a definition, and if inline is given only when the function is declared, the function is not considered an inline function, so it must be added to the function definition where the inline, At the same time, inline simply suggests to the compiler that the function be handled inline, not coerced.
2. Const: defines a constant member, including const data members and const member functions, the const data member must, and can only be initialized through the constructor's initialization list, the const member function can only access members of the class, cannot be modified, and if necessary, The following mutable keyword is introduced.
3.mutable: The introduction of this keyword is to resolve the const member function to modify the member variable, in general, the Const member function can only access the member variable and cannot be modified, but if the member variable is mutable modified, You can modify the variable in the const member function. Mutable and const cannot be used to modify member variables at the same time.
4. Static: declaring static members, including static data members and static member functions, they are shared by all objects of the class, static data members must be initialized before they are used, and static member functions can access only static data members, not non-static data members. Because the function does not contain the this pointer.
5. Virtual: declares a virtual function to implement polymorphism, which is based on a declaration.
6. Friend: declare the friend function and the friend class, which is also based on the declaration.
7. Volatile: A variable modified by this keyword means that its value may be modified outside the scope of the compiler's knowledge, so the compiler does not optimize the operation of the variable. You can also modify a variable with Const.

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.