Get the App
SLTechnology News&Howtos  ›  Development  › 

What is C++ inline function?

Shulou Source: shulou.com Published: 2022-06-02 20:03:23 09月19日 Update

This article mainly introduces "what is C++ inline function". In daily operation, I believe many people have doubts about what C++ inline function is. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the question of "what is C++ inline function"! Next, please follow the editor to study!

First, C++ inline function 1. Inline

There is the concept of macro function in C language. The characteristic of macro function is that it is embedded in the calling code, which avoids the overhead of function call. However, because the processing of macro functions occurs in the preprocessing stage, syntax detection and possible semantic errors are missing.

two。 Grammar

C++ provides the inline keyword for real embedding.

Macro function VS inline function

# include # include using namespace std / / advantages: embedded code, stack-free and stack-free overhead / / disadvantages: code replacement, easy to make the generated code larger, prone to logic errors, untyped checking # define SQR (x) ((x) * (x)) / / advantages: high abstraction, avoid repeated development, type checking / / disadvantages: stack pressing and unstack, resulting in overhead inline int sqr (int x) {return (x) * (x) } int main () {int iTuno; while (I

Tags: Functions categories code learning overhead programs compilations advantages times more types compilers disadvantages statements syntax problems help checks and then cost Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MySQL Apple Redmi Linux