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?
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).
"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).