Inline functions, templates, and header files

Source: Internet
Author: User

1) inline may be the targetCodeIncrement or decrease, depending on the size of the function to be inline.

2) inline functions that contain loops or switch statements are not worth the candle.

3) virtual and recursive functions cannot be declared as inline functions. Because the virtual function must take the address and virtual function pointer vptr in the inheritance system. Inline functions have no memory address.

4) destructor generally contain hidden code and cannot be inline. That is to say, the Destructor is defined in the. h file of the class definition with caution.

 

5) The Declaration and definition of function templates and class templates must be included in the header file. Otherwise, a connection error occurs.

 

6) The global function definition cannot be placed in the header file. Otherwise, multiple definition errors may occur when multiple implementation files contain the header file. You can declare a global function as an inline function, so that the function body can be defined in the header file.

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.