"C + + Knowledge Summary of the third" __c++

Source: Internet
Author: User
Tags function prototype
Preface:

To undertake the last one, continue to open the road of C + + summary. Text:

Chapter III Functions and function templates

Class objects typically contain data members and member functions.

C + + function parameters are delivered in two ways: value and address.

The address value is passed by the value, not the address, and the address is transmitted instead of the address value. The object address value is passed as an argument using the object pointer, and an object reference is used as an argument when the address is passed. object as a function parameter

is to pass the value of the argument object to the formal parameter object and pass it in one direction. The formal parameter has a backup of the argument. object pointers as function arguments

Takes a pointer to an object as a function argument, which is an object pointer (a pointer can point to an object's address), which is the address value of an object. reference as a function argument

The reference parameter, where the function does not initialize the formal parameter object, that is, the alias of which object the formal parameter object is not specified. When a function is called, the argument object name is passed to the parameter object name, and the Parameter object name becomes an alias for the argument object name. The argument object and the formal parameter object represent the same object, and changing the value of the Parameter object is to change the value of the argument object. Default Parameters

The default argument is that the programmer is not required to set this parameter, and the compiler assigns a default value to the parameter when needed. When programmers need to pass special values, they must be indicated. The default parameters are described in the function prototype, which can have more than 1 default parameters, but must be placed at the back of the parameter sequence. in-depth discussion function return value

The return value type of a C + + function can be any type other than a divisor group and a function. A function of a non-void type must return a value to the caller. Arrays can only return addresses. When the return value of a function is a pointer or a reference object, the function returns the object must continue to exist, not the local object within the function as the return value of the function. Inline function

Functions that are described by using the keyword inline are inline functions.

In C + +, other functions can be described as inline functions, except for functions that have circular statements and switch statements that cannot be described as inline functions.

Advantage: Use inline functions to speed up program execution, but if you have more function body statements, you increase the size of your program code. Use small inline functions to compromise the speed and size of your code, depending on whether the programmer is pursuing code speed or the size of the code.

The compiler must know the function body of the inline function in order for the inline substitution to take place. So the function must be defined before the statement that first calls the secondary function in the program. function overloads and default parameters

function overloads make a function name have a variety of functions, that is, "multiple forms", this attribute is polymorphism.

Function Overload: Parameter type and number are different.

Dynamic or late-linked: The source code indicates only the function call, not the function to which it is called. It is not possible to determine which function is invoked until the program is run, and dynamic editing requires the support of virtual functions.

Static or Advanced: The compiler, at compile time, can call a fixed function identifier based on the source code and replace them with a physical address. Occurs when the program is compiled.

With default parameters, you cannot overload a function that is less than the number of parameters.

   Epilogue:      &NBSP

                       More effort more luck                                             &N Bsp                                   &NB Sp                                   &NB Sp                                   &NB Sp                                   &NB Sp                                   &NB Sp                                   &NBsp                                   &NB Sp                                   &NB Sp                                   &NB Sp                                   &NB Sp                                   &NB Sp                                   &NB Sp                                   &NB Sp                                 &nbsp                                   &NB Sp                                   &NB Sp                                   &NB Sp                                   &NB Sp                                   &NB Sp                                   &NB Sp                                   &NB Sp                                                                  &NB Sp                                   &NB Sp                                   &NB Sp                                   &NB Sp                                   &NB Sp                                   &NB Sp  

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.