Inline Function in C++?

Hello Everyone, I want to know about the functionality of the inline function in C++. I have some interviews on skype next week and they will test my programming skills, So i am prepared myself according to it. So can anyone know what the exact syntax oo this and Is it possible for the C++ compiler to ignore inlining?
You asked basically the same thing 7 months ago.
https://www.cplusplus.com/forum/beginner/260036/

If you'd actually spent the last 6 months coding real C++ programs, you'd know all this stuff.
You need to live and breath this stuff every day.
Not try and cram sound-bite facts in the previous 24 hours.

if they are asking about inline, you may not want to work there. Its a tool left over from the early-mid 90s or earlier when compilers were dumb. Ive had zero luck with it in many, many years on newer compilers.

its not a function. The fact that it is not a function, and your question (this isnt a test of your skill, its either a nonsense trip up question or a relic), show that you do not know c++ and should not apply for a job that uses it.

inline is a keyword, which tells the compiler to consider making the code there inline. The compiler can, and usually does, ignore this. Some language extended compilers have some sort of forced inline statement (more of a compiler flag than a keyword for those, eg __forceinline from microsoft) that is only ignored if not possible (do you know when it is not possible to inline?!). You can also force inline yourself by exploiting the language features (which can't be done in the impossible cases, of course: it will die in the compiler).
Last edited on
"inline" is a keyword. Functions declared with the inline keyword are inline functions.

The inline keyword is a way to circumvent the one definition rule (ODR). Multiple definitions of things are usually not allowed but if you mark the function or variable with inline it will allow you to have multiple definitions (in different translation units) as long as they are all the same (this is usually not checked so be careful). This allows you to define functions and variables directly in header files without using a .cpp file. Member functions that are defined directly inside a class definition are automatically inline (assuming you're not using C++20 modules).
Last edited on
This is with reference to Peter's reply.

Variables can be declared with the inline keyword as well? What's the use of doing that though?
same as what it does for functions, you get to define the variable in a header file.
Even though it is possible to call an inline function from within itself in C++, the compiler may not generate the inline code. This is so because the compiler won’t be able to determine the depth of the recursion at the compile time. All this information I got from the list of questions this https://hackr.io/blog/cpp-interview-questions
Topic archived. No new replies allowed.