In depth understanding of common keyword meanings in C++

  • 2020-04-01 23:37:37
  • OfStack

1. The inline: Define inline function. This keyword is based on the definition. If you only give inline when the function is declared, the function will not be considered inline.
2. The const: Define members, often including the const data members and const member function, const data members must, can only through the constructor initialized initialization list, const member functions can only access to the members of the class, cannot be modified, if need to modify, will introduce the following mutable keyword.
3. The mutable: The introduction of the key is to solve the const member function to modify a member variable, usually, const member functions can only access member variables, cannot be modified, but if the member variables are mutable modification, can modify the variable in the const member functions. Mutable and const cannot be used to modify the member variable.
4. The static: Declare static members, including static data members and static member functions, which are Shared by all objects in the class. Static data members must be initialized before use, and static member functions can only access static data members, not non-static data members, because the function does not contain this pointer.
5. Virtual: Declare a virtual function, which is used to implement polymorphism, and the keyword is declarative.
6. Friend: Declare friend functions and friend classes. This keyword is also declarative.
7. Volatile: A variable modified by this keyword is one whose value may be modified outside the scope of the compiler's knowledge, so the compiler does not optimize the operations performed on this variable. You can modify a variable at the same time as const.

Related articles: