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