Inline Member Functions (C++)

A member function that is both declared and defined in the class member list is called an inline member function. Member functions containing a few lines of code are usually declared inline.

An equivalent way to declare an inline member function is to declare it outside of the class declaration using the keyword inline and the :: (scope resolution) operator to identify the class the member function belongs to. For example:

class Y
{
      char* a;
public:
      char* f() {return a;};
};

is equivalent to:

class Z
{
      char* a;
public:
      char* f();
};
inline char* Z::f() {return a;}

When you declare an inline function without the inline keyword and do not define it in the class member list, you cannot call the function before you define it. In the above example, you cannot call f() until after its definition.

Inline member functions have internal linkage. Noninline member functions have external linkage.



C++ Inline Functions