In function.h file I have declared a function as inline such as
inline double foo(int &a)
{
return a*double value
}
In a.cpp file I have included function.h file and call foo function in many places.
a.cpp file also has an instance of class b and I want to call the foo function in b instance. When I call a function in b, I’d like to pass the function pointer to the b so that I can call the foo function in b without including function.h file.
b.cpp file
void b_foo(a function pointer to foo function)
{
call foo
}
Since I have declared the function as inline, I am not sure if passing the function pointer is efficient rather than just including function.h file in b.cpp.
I’d like to see what might be the difference.
Whether it makes a real performance difference you can only find out by implementing both versions, turning on compiler optimization and comparing the speed. It depends on too many factors related to the rest of your code to be predictable. It obviously depends in particular on how many times your function is actually called.
But generally speaking, inlining is likely to have a major positive impact on speed.
To keep things flexible, and given that you are apparently using C++ (rather than C), it would be a good idea to use more C++-like ways of dealing with this situation. See this SO post for various possibilities and what they mean. If you follow one of the strategies outlined in the question there, chances are the compiler will inline wherever possible while you still get the flexibility of a function pointer.