Static inline functions in class

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

Answers (5)

4pie0
4pie0

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

Wojtek Surowka
Wojtek Surowka

Reputation: 21013

Static functions can be inline the same as all other functions. However, for your use case namespace is better solution.

Upvotes: 1

Zac Howland
Zac Howland

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

Jarod42
Jarod42

Reputation: 218333

static function/method may be inline too.

And methods defined inside the class are inline by default.

Upvotes: 2

DmitryARN
DmitryARN

Reputation: 648

but static methods can not be inlined since I know

That's not true, static methods can also be inline.

Upvotes: 1

Related Questions