In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is to share with you the content of the example analysis of function modifiers in C++. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Before the function name
1. Return value type
The return value type is an essential part of defining functions in C++. These modifiers include built-in basic data types and custom types such as void, (unsigned) int,bool, as well as modified return value const keywords (such as const int*), as well as the new type derivation auto keyword added in Candles11.
2 、 template
The template keyword declares that the function is a template function.
3 、 virtual
The virtual keyword declares that the function is a virtual function and can be overridden by subclasses.
4 、 inline
The inline keyword prompts the compiler to inline the function.
5 、 static
When static modifies the member function of a class, it indicates that the function is a static member function and is not subordinate to a specific object; when modifying a separate function, the visible scope of the function is limited to this file.
6 、 extern
The extern keyword declares a function defined externally
7 、 explicit
The explicit keyword is added in Category 11 and is used only for constructors, specifying that constructors are explicitly defined and cannot be implicitly converted.
8 、 friend
The friend keyword declares the friend function of the class, within which you can directly access the private or protected members and member functions of the object.
9 、 constexpr
A new addition in Category 11 instructs the function to return a constant expression (which can be simply understood as returning a literal quantity).
After the function name
There are two kinds of modifiers that are placed after the function name, the first using the equal sign (=) and the second being directly modified.
1. Use the equal sign
This class is relatively simple, and there are three types:
= 0: can only be used for virtual functions, indicating that the function is a pure virtual function.
= default:C++11 is new and can only be used for special member functions that the compiler provides a default implementation, indicating that the default implementation is used.
= delete:C++11 is new and can only be used for special member functions that the compiler provides a default implementation, indicating that the compiler should delete the default implementation of the function.
2. Direct modification
There are many kinds of modifiers. The modifiers I know include:
Const
Indicates that the function will not modify the object (or the object will not change during the call). Note that the member variables modified by mutable are not included. Please refer to my previous article: mutable and volatile in C++.
Volatile
Similar to const-modified functions, the state of the object may change at any time; const-modified functions can only call their own const member methods, similarly, volatile functions can only call their own volatile member functions.
&
The function introduced by Clover 11 indicates that the function can only be called by the left-value object by referring to the qualifier.
& &
Cantilever 11 is introduced, and the right value refers to the qualifier, indicating that the function can only be called by the right value. If the function is not decorated with reference qualifiers, both the left and right values can be called. An example of reference qualification:
# include struct S {void f () & {std::cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.