PKU C + + program Design Internship Study notes

Source: Internet
Author: User

1.7 inline functions and overloaded functions

Inline functions: Function calls are time-overhead. If the function itself has only a few statements, executes very quickly, and the function is executed many times over and over again, the cost of invoking the function will be quite large.

In order to reduce the cost of function calls, an inline function mechanism is introduced. When the compiler processes the call statement for an inline function, it inserts the entire function's code into the calling statement without generating the statement that invokes the function.

Overloaded functions: One or more functions with the same name, however, the number of arguments or the type of the parameter is different, which is called the overload of the function. The compiler determines which function should be called based on the number and type of arguments in the calling 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 (2,4); Call (2) Max (A/n); Call (3) Max (3,2.4); Error, ambiguity, can either type after the conversion of the call (1), or the type can be converted after the call (2)

1.8 Function Default Parameters

In C + +, when defining a function, you can make the right-most successive arguments with default values, then when calling the function, if the corresponding position does not write the parameter, the parameter is the default value.

function parameters can be used by default to improve the extensibility of the program. That is, if a well-written function is to add a new parameter, and the original statement that called the function does not necessarily need to use the new parameter, then the default parameter can be used to avoid modifications to the original function call statements.


2.1 Object-Oriented programming method for object-oriented program design


Four basic concepts of object-oriented: abstraction, encapsulation, inheritance, polymorphism

Abstract: The common attributes of a class of objective things are summed up to form a data structure. Some of the behaviors and operations that can be done by such things can be summed up to form functions that manipulate specific data structures.

Inheritance: The data structures and algorithms are tied together to form classes.


PKU C + + program Design Internship Study notes

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.