What are the in-line and not in-line method definitions (member function) in C++, and what is the difference between them? please provide some examples for both, thanks!
Asked
Active
Viewed 46 times
1 Answers
-1
In C++ inline functions just start with the word inline. For example inline void myFunc()
Inline is a hint to the compiler that instead of calling this function via a call opcode when it compiles it, that it should instead insert the code of the function anywhere its called. This reduces the overhead of calling the function at the cost of additional executable size.
Notice I said its a hint. The compiler does not have to follow it. It will use its own best judgement on whether you're right or not. Really except in very niche circumstances you shouldn't be doing this, let the compiler decide when its more optimal to inline or not.

Gabe Sechan
- 90,003
- 9
- 87
- 127
-
2The OP is specifically asking about member functions. These can be inline without starting with the `inline` keyword. – john Sep 11 '22 at 06:33
-
@john any function can be inlined without the inline keyword. The compiler can make that call. – Gabe Sechan Sep 11 '22 at 15:13
-
I realise that but I mean inline as defined by the C++ standard, not whether a compiler actually inlines a call to a function or not. A method declared inside of a class definition is inline in this sense, even though the inline keyword is not used. I'm sure you know this but the OP probably doesn't and so your answer might be confusing. – john Sep 11 '22 at 15:45