Reputation: 587
I want to group my math functions. My math functions include many mathematical functions including the functions in "math.h" and some constant values. They are not in a class or namespace. Due to performance reasons, they are all inlined. But I want them grouped in a class if not possible namespace instead. I just want to use my functions like this:
MyMath::Pow(2, 2);
MayMath::PI;
So my question is; If I can use class, functions and values must be static I think but static methods can not be inlined since I know. I can use "MyMath" as a namespace if we can not find a solution.
Upvotes: 0
Views: 1205
Reputation: 29764
static inline
is perfectly valid.
If the storage class is extern, the identifier has external linkage and the inline definition also provides the external definition.
If the storage class is static, the identifier has internal linkage and the inline definition is invisible in other translation units.
In fact this is rare to use inline
with storage class different from static
.
Upvotes: 0
Reputation: 21013
Static functions can be inline the same as all other functions. However, for your use case namespace is better solution.
Upvotes: 1
Reputation: 15870
This sounds like an XY Problem.
You are attempting to put standalone functions (that do not belong in a class), inside a class - presumably because you are coming from another object-oriented language that does not let you write standalone functions.
To write a math library that includes functions like pow
, exp
, log
, etc., create the namespace MyMath
and define the functions. There is no need for a class.
Upvotes: 3
Reputation: 218333
static function/method may be inline too.
And methods defined inside the class are inline by default.
Upvotes: 2
Reputation: 648
but static methods can not be inlined since I know
That's not true, static methods can also be inline.
Upvotes: 1