# C++ inline keyword **[inline keyword](https://en.cppreference.com/w/cpp/language/inline)** marks a function to permit multiple definitions across translation units and allows the compiler to consider inlining (replacing the call with the function body). Today, `inline` is mainly for allowing definitions in headers; the actual inlining decision is made by the optimizer regardless of the keyword. Use `inline` on function definitions in headers, or use `constexpr` and templates which are implicitly inline. ## Example This example shows inline functions in headers avoiding ODR violations. ```cpp // compile: g++ -o inline inline.cpp math.cpp // run: ./inline // description: inline allows function definitions in headers #include // Allowed in header due to inline inline int square(int x) { return x * x; } // Modern alternative: constexpr (implicitly inline) constexpr int cube(int x) { return x * x * x; } int main() { std::cout << "square(5): " << square(5) << "\n"; std::cout << "cube(3): " << cube(3) << "\n"; return 0; } // math.cpp can define other inline functions from the same header ```