Member function inlining functions

11. The following description of the characteristics of a member function, ______ is wrong.  

  1. Member function must be inline   B. member functions can be overloaded    

C. member functions may be provided D. default parameter values may be static member function    [A]

[D] as defined in the class member functions in vivo, in vitro can also be defined in the class, it is not necessarily a member function inline function; overloaded member functions, can set the default value of the parameter, static member functions.

 

Inline function refers to a function when calling wardrobe, do not regard him as the call processing, but the code calling this function directly in his function in expanded form, can be understood as an inline function is equivalent to a piece of code . No need to call, efficiency is higher. Member function is a function declared in the class, it belongs to the class. Of course, if the member functions defined in the class is automatically changed to inline functions.

 

Member function is part of the object, static function is part of the class. If the class of functions defined by the body, it will be the default compiler to inline functions , if the definition of the function on the outside, and is a function of the time in a statement with the keyword inline, the function becomes an inline function , otherwise the member function.

 

Inline function is similar to the inside of the C macro, but often have some macro insecurity, such as macro definition add () is a + b, when calling macro definition are in direct, without any determination, if the call res = add ( ) * c; the code is obtained res = a + b * c; not the desired result. 
   Inline functions can be understood as a safe macro definition, he is a real function, but do not push the stack, fast, and secure than the macro definition, the use of short and relatively high frequency function can be written inline functions inline . 
   Inline function at compile time, will this inline function code is compiled directly to the calling function place. Reduce the jump, push and other data when a function call operator. So call compared to the number of rows, the efficiency of inline functions to be relatively high. But because of this, the final generation of the program files to be slightly larger.
 
1. Inline cpu may reduce system overhead, and increase the speed of the overall process, but when a large inline functions, have the opposite effect, it is generally used only relatively small inline functions.
2. There are two ways inline function declaration, a method is used before inline function key; the other is the internal code for the function defined in the class, this function will automatically converted to inline functions, but not necessary to inline in front of the function.
3. Inline is a request to the compiler, as the same register specifier. The following circumstances will prevent the compiler to obey this request. If the function is included in the cycle, switch or goto statement, a recursive function, a function containing the static.

Guess you like

Origin www.cnblogs.com/yan-hui/p/11407252.html