+ 8

is it mandatory to define a member function outside the class

in a challenge they said every function defind inside the class is an inline function I read about inline function if the body of defined function is small , it is better make it inline so that the compiler deal with it as macros anyway it is bad to define a big function inline so should I define the function outside the class

21st Aug 2019, 9:40 PM
ABADA S
ABADA S - avatar
8 Respostas
+ 2
Outside the class is most common for all but the most trivial functions I'd say.
21st Aug 2019, 11:14 PM
Sonic
Sonic - avatar
+ 4
but I can use inline keyword inside the class why all of them are inline without writing inline before them if the compiler really considers that I will get my answer
21st Aug 2019, 9:46 PM
ABADA S
ABADA S - avatar
+ 4
thanks master HonFu [#GoGetThatBugChamp!] precious information
21st Aug 2019, 11:03 PM
ABADA S
ABADA S - avatar
+ 4
another precious information thanks Sonic .. but it is good practice to define it outside the class isn't it? what about structures is it the same?
21st Aug 2019, 11:11 PM
ABADA S
ABADA S - avatar
+ 4
I got it .. I appreciate your information
21st Aug 2019, 11:16 PM
ABADA S
ABADA S - avatar
+ 3
If your function contains a loop or recursion or a switch or goto, the compiler may not decide to inline it.
21st Aug 2019, 11:09 PM
Sonic
Sonic - avatar
+ 2
If you write it in the class, it will be inline automatically. If you write it outside of the class and want it to be inline, you have to explicitly say it.
21st Aug 2019, 11:01 PM
HonFu
HonFu - avatar
+ 1
From what you wrote, one can deduce: If the body is big - yes.
21st Aug 2019, 9:43 PM
HonFu
HonFu - avatar