What is the difference between the inline function and the general function

Source: Internet
Author: User

1. For example:
1 int g (int23     return x +4  56int7     8  return9


1 int  23     return x +4






Now the compiler will automatically decide whether to do the above for the function, instead of adding inline to the previous one. That is, inline functions are typically used only when the content of the function is very simple, because the code of the inline function expands wherever it is called, and if the function is too complex, the consequences of code bloat are likely to outweigh the benefits of increased efficiency. The most important place to use the inline function is the access function for the class.



A function can only be defined once in a CPP file of an executable file. If you define a function in a. h file and have two CPP included, it will cause the function to be defined in two CPP to produce an error. But the inline function is allowed to be defined more than once in multiple CPP, which solves the problem.


Attached: Baidu Library Inline (http://baike.baidu.com/link?url=ht_ B0VB9EEBXNSR9JQ8DM6K1OZMAP-HO3IWPHJFLI2ABVSIPULIUOPBKWOIBXPK1DRK8SJGM7IZN_L2C516G5Q), in more detail.


What is the difference between the inline function and the general function

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.