Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you inline static member functions?

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?

like image 477
John Avatar asked Feb 11 '12 22:02

John


People also ask

What limitations does a static member function have?

A static member function can access only the names of static members, enumerators, and nested types of the class in which it is declared. Suppose a static member function f() is a member of class X . The static member function f() cannot access the nonstatic members X or the nonstatic members of a base class of X .

Can a static function be virtual?

A virtual function cannot be global or static because, by definition, a virtual function is a member function of a base class and relies on a specific object to determine which implementation of the function is called.

Are member functions inline by default?

A class member function defaults to external linkage unless a definition for that function contains the inline specifier.

Can we overload static member functions?

Can we overload static methods? The answer is 'Yes'. We can have two or more static methods with the same name, but differences in input parameters.


1 Answers

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.

like image 129
Seth Carnegie Avatar answered Oct 11 '22 15:10

Seth Carnegie