c++inline-method

Calling inline functions C++


I have an inline member function defined under class MyClass

int MyClass::myInlineFunction();

This function is called from several places in my code.
There are two ways to call this function
Case 1: Using this every time the function is called.

 mobj->myInlineFunction() ;

Case 2: Assign the result of this function to a variable and use it for subsequent accesses

 var = mobj->myInlineFunction() ;

Which one should be preferred??


Solution

  • Case 2 can give you a lot of performance, if the function does something that takes some time. Choose it if