Considerations for using inline functions

Source: Internet
Author: User

Class Tableclass
{
Private
int i,j;
Public
int Add () {return i+j;}
inline int Dec () {return i-j;}
int Getnum ();
}
inline int Tableclass::getnum ()
{
return I;
}

The three functions stated above are inline functions.

Attention:

1, in C + +, within the class definition of the function body function, is implicitly considered to be inline function. Regardless of whether there is a inline keyword.

2, if the definition of the function is placed outside the class, the function definition must be added before inline to become an inline function, and the function declaration can be added inline also can not add

3, the keyword inline must be placed with the function definition body to make the function inline, only put the inline in front of the function declaration does not have any effect .

So, inline is a "keyword for implementation", not a "keyword for declaration". Generally, users can read the declaration of a function, but do not see the definition of the function. Although the inline keyword is added to the declaration and definition of the inline function in most textbooks, I don't think inline should appear in the declaration of the function. This detail does not affect function, but it embodies a basic principle of high quality C++/C programming style: Declaration and definition can not be confused, users do not need, and should not know whether the function needs to inline. -Excerpted from the high Quality C++/C Programming Guide

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.