Can you inline static member functions?

16

I have a static member function which is merely syntactic sugar for me and I would like its body to appear in place of going through the motions of passing parameters to it. Will

inline static foo(int a) {return a & 0x00000040;}

be inlined just as it would if it was inline without being static?

c++
inline
static-methods
asked on Stack Overflow Feb 11, 2012 by John

2 Answers

18

The compiler chooses what it wants to do so we can't say what it will choose to do. That said, the function being static will not prevent it from being inlined; static functions are basically free functions with a different naming style and access to the class' private members.

answered on Stack Overflow Feb 11, 2012 by Seth Carnegie • edited Feb 11, 2012 by Seth Carnegie
3

A static member method has no this parameter, and can therefore only access static member variables.

It is distinct from whether the method is inlined or not. So the two are independent of each other.

The compiler decides if a method is going to be inlined or not. Your use of the keyword is merely a hint to the compiler.

answered on Stack Overflow Jun 12, 2013 by dabble53 • edited Jan 29, 2016 by Benjamin W.

User contributions licensed under CC BY-SA 3.0