Inline function

Hi There,

In modern C++ do we still use inline function?
Like in this format?

1
2
3
4
  inline float nameOfFunction(float kg)
{
 return 60 * kg;
}


Thanks :)
Yes, inline functions are an important part of header-only libraries (like the majority of boost).

The keyword inline permits multiple definitions, and that's what you get when you put something in a header and include that header in more than one file.

Now that C++17 also allows inline variables, even more libraries can be made header-only.
Yes, but it is only a suggestion to the compiler, not a command.
Some compilers allow a forceinline command, that is enforced if possible (it can't be for recursive functions, and a few other reasons).

You can also force inline by hand by exploiting # includes. This is crude, and only useful in extreme situations where you must have the performance, and you can demonstrate that your inline force is better than whatever the compiler does normally (this is very rare today, it was useful 25 years ago).

looks like this..
(text file named x.inc)
c++ statements;

main file..

code;
#include "x.inc"
morecode;
#include "x.inc";
etc;

Topic archived. No new replies allowed.