4

When writing C++ code within the CLion IDE one of the Clang-Tidy messages that comes up is this function can be made static. Is there any benefit (mainly performance?) for making this function static, if it won't be used outside the class and thus, removes one of the main uses of static functions.

Danke

10
  • No this pointer will be passed to a static function, so technically you save performance Commented Dec 8, 2021 at 20:15
  • 4
    Essentially if your class method does not require state (in other words does not require this nor does it access/mutate any data members) then the function should either be static or often a free-function within a namespace Commented Dec 8, 2021 at 20:17
  • @CoryKramer I understand that the function could be made static, but my main curiosity is there any benefit to making it static? Just for the explicitness to state that this member function does not require any member variables? Commented Dec 8, 2021 at 20:20
  • 2
    Put the question the other way around: should I define a function so that it takes arguments that it won't use? Commented Dec 8, 2021 at 20:35
  • 1
    It is a matter of preference, don't sweat over it. Commented Dec 8, 2021 at 22:28

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.