O'Reilly logo

Efficient C++ Performance Programming Techniques by David Mayhew, Dov Bulka

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

What Is Inlining?

Inlining replaces method calls with a macro-like expansion of the called method within the calling method. There are two mechanisms for specifying an intent to inline. One is to prefix the method definition with the reserved word inline, and the other is to define the method within the declaration header. A code sample make this easier to demonstrate:

Class GatedInt {
    int x;
public:
    int get () {
        return x;
        }
    void set (int arg) {
        x = arg;
        }
}

GatedInt::get and GeatedInt::set will both be inlined because they are defined within the declaration. Conversely, the methods to be inlined can be defined outside the class declaration but within the header file or within a file included by the header file.

 Class GatedInt { int x; public: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required