Possible Duplicate:
c++ inline function?
What is the the real concept of inline function.
i really unable to understand the inline function.
why & where should i use inline function? How it is differ from normal function?
Edit: what is difference between macro & inline function?
The main language difference between an inline and a non-inline function is that inline functions are exempt from the one-definition rule, provided all definitions are the same.
This is a crucial feature for C++, since it allows you to write member function definitions inside class definitions and still be able to include the class definition in a header file.
Consider this header:
stupid.h is not usable if you have to include it more than once, because you’ll end up with multiple definitions of
foo. Making the declarationinlinelets you get around this problem. Applying the same logic to a class definition (remember that all member functions that are defined inline are implicitly declaredinline), this allows us to write this:We can include works.h in as many translation units as we like, and there’s no “multiple definition” error for
Foo::fandFoo::g, because those are (implicitly) declared inline.Of course
inlinealso serves as a hint to the compiler to replace function calls by copies of the function body, but the compiler can choose to do or not do that pretty much independent of whether or not you declare a functioninline.