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: ...
Get Efficient C++ Performance Programming Techniques now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.