Pku c ++ Program Design Study Notes

Source: Internet
Author: User

Pku c ++ Program Design Study Notes
1.7 inline and overloaded functions

Inline functions: function calls have time overhead. If a function has only a few statements, the execution is very fast, and the function is repeatedly executed many times, the overhead produced by calling the function will appear relatively large.

To reduce the overhead of function calls, the inline function mechanism is introduced. When the compiler processes a call statement for an inline function, it inserts the code of the entire function into the call statement without generating a function call statement.

Overload function: one or more functions with the same name, but the number or type of parameters are different. This is called a function overload. The compiler determines which function to call based on the number and type of real parameters in the call statement.

 

(1) int Max (double f1, double f2) {} (2) int Max (int n1, int n2) {} (3) int Max (int n1, int n2, int n3) {} Max (3.4, 2.5); // call (1) Max (); // call (2) Max (, 3 ); // call (3) Max (3, 2.4); // error, ambiguity, which can be called after type conversion (1) or after type conversion (2)

 

1.8 default function parameters

 

In C ++, when defining a function, several consecutive parameters on the rightmost side can have default values. When calling a function, if no parameter is specified at the corresponding position, the parameter is the default value.

Function parameters can be defaulted to improve program scalability. That is to say, if you want to add new parameters to a function, but the statements that call the function do not need to use new parameters, in order to avoid modifying the original function call statements, you can use the default parameter.

 

2.1 object-oriented programming methods

Four basic object-oriented concepts: abstraction, encapsulation, inheritance, and Polymorphism

Abstract: sums up the common attributes of a type of objective things to form a data structure. Summarize the behaviors and operations that can be performed by such things to form functions that can be used to operate on specific data structures.

Inheritance: binds data structures and algorithms to form classes.

 

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.