Why a function defined in a class is inline by default

Source: Internet
Author: User
1. The first thing to note is that an inline function has a static link (static linkage) and is not visible to anyone other than the file. 2. Compilation is a sub-module (different compilation modules refer to different files), using # include to include the header file of the class, in the preprocessing phase will be replaced by text. If a function of the class is defined in the. h file at this time, the file containing the inlcude will be compiled with the function definition written to the. Symtab symbol table in the target file of the compilation module. Now, if the function definition in the. h class is not inline, the function symbol symbol in the. Symtab is exposed outward. If multiple files include the header files of the class, the function symbol is exposed in their respective target files.     This will cause a redefinition error to occur during the connection process. So, we'll see in the deep C + + object model that the compiler constructor the default constructor when compositing the default, destructor,assignment copy operator is done with inline, and if the function is too complex to fit inline, a explicit non-inline static instance is synthesized.

Why a function defined in a class is inline by default

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.