If you define your member function inside class declaration , they are implicitly inline.

The inline function is supposed to improve the performance by embedding the function body to calling place and so reduce calling cost. It has two disadvantages: add the size of the program and change of the inline function will make caller recompile.

The rule is only inline the function that tiny and don't change constantly. Functions should only contains one or two expressions, any size larger than that don't benefit from inlining.

inline example

Use inline specifier to make a function inline:

 
inline int foo( int i) {
    return i*i;
}
 
#include <iostream>
using namespace std;
 
void main() {
    cout << foo(3) << endl;
    int i;
    cin >> i;
    cout << foo(i+2) << endl;
}
 
//calling code will be replaced like this:
 
void main() {
    cout << (3)*(3) << endl;
    int i;
    cin >> i;
    cout << (i+2)*(i+2) << endl;
}
 
 

How compiler optimize your program by inline

In C++ Standard , inline just advise the compiler to expand it, not require. Compiler vendor may not expand the function even it declared with inline, and may expand some functions even if they are not declared with inline.